SỞ GD&ĐT NINH BÌNH
HDC ĐỀ THI CHỌN HSG LỚP THPT
Kỳ thi thứ nhất - Năm học 2015 – 2016
MÔN: TIN HỌC
Ngày thi 06/10/2014
(hướng dẫn chấm gồm 06 trang)
Câu
1
Code
Program Nttd;
const fi='nttd.inp';
fo='nttd.out';
Var M,N,d,i,dem: longint;
f,g: text;
6 điểm
{------------------------------------}
Function USCLN(m,n: longint): longint;
Var r: longint;
Begin
While n<>0 do
begin
r:=m mod n; m:=n; n:=r;
end;
USCLN:=m;
End;
{------------------------------------}
BEGIN
dem:=0;
assign(f,fi); reset(f);
assign(g,fo); rewrite(g);
read(f,M,N);
d:= USCLN(M,N); i:=2;
While d<>1 do
begin
If d mod i = 0 then
begin
dem := dem + 1;
While d mod i= 0 do d:=d div i;
While M mod i = 0 do M:=M div i;
While N mod i = 0 do N:=N div i;
end;
Inc(i);
end;
if M * N = 1 then write(g,dem)
else write(g,0);
close(f); close(g);
END.
1
2
const
fi= 'CATGO.inp';
fo= 'CATGO.out';
var
a:array[1..20] of longint; //gia tri cua cac so
T:array[1..21] of longint; // tong cac gia tri trong nhom
x:array[1..20] of longint; // vector nghiem
n,k: longint;
curent: longint; // so lon nhat hien tai da su dung trong
// vector nghiem
f,f2:text;
ketqua : boolean;
{------------------}
procedure nhap;
var i: longint;
begin
assign(f,fi); reset(f);
readln(f,n,k);
for i:=1 to n do
read(f,a[i]);
close(f);
end;
{---------------------}
function kt:boolean;
var i: longint;
begin
for i:=1 to K-1 do
if t[i]<>t[i+1] then exit(false);
exit(true);
end;
{--------------------}
procedure inkq;
var i,j: longint;
begin
assign(f,fo); rewrite(f);
for i:=1 to k do
begin
for j:=1 to n do
if x[j]=i then write(f,a[j],' ' );
writeln(f);
end;
close(f); close(f2);
halt;
end;
{--------------------}
procedure backtrack(i:longint);
var j: longint;
begin
//neu i la vi tri gioi han cuoi cung cua curen+1
//thi gan vi tri i cho curent+1
if (i= n-k+curent+1) and (curent
2
6 điểm
begin
inc(curent);
x[i]:=curent;
t[curent]:=t[curent]+a[i];
if i= n then
begin
if kt then ketqua := true;
end
else backtrack(i+1);
t[curent]:= t[curent]-a[i];
dec(curent);
end
// neu khong phai la vi tri gioi han cua curen+1 thi
// x[i] co the nhan cac gia tri tu 1 -> curen+1
else
begin
for j:=1 to curent+1 do
begin
if j>K then exit; // neu j da lon hon K thi x[i] khong nhan
if j=curent+1 then // neu x[i] nhan gia tri curen+1
begin
// thi phai tang curent hien tai len 1 don vi
x[i]:=j ;inc(curent);
t[j]:= t[j]+a[i];
if i= n then
begin
if kt then ketqua := true ;
end
else backtrack(i+1);
t[j]:=t[j]-a[i];
dec(curent);
end
else
// neu khong thi khong tang gia tri curent
begin
x[i]:=j ;
t[j]:= t[j]+a[i];
if i= n then
begin
if kt then ketqua := true ;
end
else backtrack(i+1);
t[j]:=t[j]-a[i];
end;
end;
end;
end;
{----------------}
3
Procedure sx;
Var i,j: longint;
Tg:longint;
Begin
ketqua := false;
For i:=1 to n-1 do
For j:=i+1 to n do
if a[i]>a[j] then
begin
tg:= a[i]; a[i]:=a[j]; a[j]:=tg;
end;
End;
begin
nhap;
sx;
curent:=0;
backtrack(1);
assign(f,fo); rewrite(f);
if ketqua then writeln(f,'1') else write(f, 0);
close(f);
end.
3
8 điểm
program SCLN;
uses crt;
const maxn = 251;
fi = 'SCLN.INP';
fo = 'SCLN.OUT';
var pa : array[0..maxn,0..maxn] of byte;
s1,s2,skq : string;
max : byte;
{============================================}
procedure docf;
var f : text;
begin
assign(f,fi);
reset(f);
readln(f,s1);
read(f,s2);
close(f);
end;
function maxso(a,b:byte) : byte;
begin
maxso := (abs(a-b)+a+b) div 2;
end;
{============================================}
procedure Idonotknow;
4
var i,j : byte;
begin
for i := length(s1) downto 1 do
for j := length(s2) downto 1 do
if s1[i] = s2[j] then pa[i,j] := pa[i+1,j+1] +1
else pa[i,j] := maxso(pa[i+1,j] , pa[i,j+1] );
max := pa[1,1];
end;
{============================================}
procedure wastingtime;
var ch
: char;
i,j,so,is,js : byte;
begin
is := 1; js := 1;
so := 0;
repeat
for ch := '9' downto '0' do
begin
i := is; j := js;
while (s1[i] <> ch)and(i <= length(s1)) do inc(i);
while (s2[j] <> ch)and(j <= length(s2)) do inc(j);
if pa[i,j] = max - so then
begin
skq := skq + ch;
is := i+1; js := j+1;
break;
end;
end;
inc(so);
until max=so;
while (skq[1] = '0')and(skq<>'0') do delete(skq,1,1);
end;
{============================================}
procedure ghif;
var
f :
text;
begin
assign(f,fo);
rewrite(f);
if max = 0 then write(f,0)
else
begin
wastingtime;
write(f,skq);
end;
close(f);
end;
{============================================}
BEGIN
docf;
idonotknow;
5
ghif;
END.
Xây dụng bộ test trên đĩa CD kèm theo chấm bằng tự động bằng phần mềm themis.
Câu 1 24 test mỗi test 0.25 điểm
Câu 2 24 test mỗi test 0.25 điểm
Câu 3 32 test mỗi test 0.25 điểm
Thời gian mỗi test ………nếu quá thời gian thì không tính điểm.
-----------Hết-----------
6