Câu 1:
type int = longint;
type bool = boolean;
const prefix = 'DTHCN';
fi = prefix + '.INP';
fo = prefix + '.OUT';
var a, b, n: int;
begin
assign(input, fi); assign(output, fo);
reset(input); rewrite(output);
readln(a, b);
n:=a + b;
write(n div 2, ' ', n div 2 + n mod 2);
close(input); close(output);
end.
Câu 2:
- Cách 1: Lấy ra từng hậu tố của S để tìm độ dài tiền tố chung
type int = longint;
type bool = boolean;
const prefix = 'SIMI';
fi = prefix + '.INP';
fo = prefix + '.OUT';
var s, ss: ansistring;
i, r: int;
function f(x: ansistring): int;
var i: int;
begin
for i:=1 to length(x) do
if x[i] <> s[i] then exit(i - 1);
exit(length(x));
end;
begin
assign(input, fi); assign(output, fo);
reset(input); rewrite(output);
readln(s);
for i:=length(s) downto 1 do begin
ss:=s[i] + ss;
inc(r, f(ss));
end;
writeln(r);
close(input); close(output);
end.
// O(n*(n+1)/2)?
- Cách 2: Sử dụng mảng băm kết hợp chặt nhị phân
type int = longint;
type bool = boolean;
const prefix = 'SIMI';
fi = prefix + '.INP';
fo = prefix + '.OUT';
const base = 31;
const M = trunc(1e9) + 7;
var s: ansistring;
i, res, n: int;
H, po: array[0..10000] of int64;
function hash(i, j: int): int64;
begin
exit((H[j] - H[i - 1] * po[j - i + 1] + M * M) mod M);
end;
procedure init;
begin
po[0]:=1;
for i:=1 to n do begin
po[i]:=(po[i - 1] * base) mod M;
H[i]:=(H[i - 1] * base + ord(s[i]) - ord('a')) mod M;
end;
end;
function f(ss: int): int;
var l, r, mid: int;
begin
l:=0; r:=n - ss + 1;
while l <= r do begin
mid:=(l + r) shr 1;
if hash(1, mid) = hash(ss, ss + mid - 1) then l:=mid + 1 else r:=mid - 1;
end;
exit(l - 1);
end;
begin
assign(input, fi); assign(output, fo);
reset(input); rewrite(output);
readln(s); n:=length(s);
init;
for i:=1 to n do begin
inc(res, f(i));
end;
writeln(res);
close(input); close(output);
end.
// O(|S|log(|S|))?
Tin học, tiếng Anh: informatics, tiếng Pháp: informatique, là một ngành khoa học chuyên nghiên cứu quá trình tự động hóa việc tổ chức, lưu trữ, xử lý và truyền dẫn thông tin của một hệ thống máy tính cụ thể hoặc trừu tượng (ảo). Với cách hiểu hiện nay, tin học bao hàm tất cả các nghiên cứu và kỹ thuật có liên quan đến việc mô phỏng, biến đổi và tái tạo thông tin.
Nguồn : Wikipedia - Bách khoa toàn thưLớp 8 - Năm thứ ba ở cấp trung học cơ sở, học tập bắt đầu nặng dần, sang năm lại là năm cuối cấp áp lực lớn dần nhưng các em vẫn phải chú ý sức khỏe nhé!
Nguồn : ADMIN :))Copyright © 2021 HOCTAP247