HD chấm đề thi chính thức Hướng dẫn chấm có 04 trang Câu 1.[r]
Trang 1SỞ GIÁO DỤC VÀ ĐÀO TẠO
TỈNH YÊN BÁI
HD chấm đề thi chính thức
(Hướng dẫn chấm có 04 trang)
HƯỚNG DẪN CHẤM
KỲ THI CHỌN HỌC SINH GIỎI LỚP 12 THPT
NĂM HỌC 2012 – 2013 Môn thi: TIN HỌC 12
Ngày thi: 08/10/2012
Uses Crt;
Const
fi='KD.inp';
fo='KD.out';
Nmax=1000+2;
Var
f: text;
a: array[1 Nmax,1 Nmax] of longint;
m,n: longint;
MAX: array[1 Nmax] of longint;
Procedure doctep;
var i,j: longint;
Begin
Assign(f,fi);
Reset(f);
Readln(f,m,n);
For i:=1 to m do
For j:=1 to n do read(f,a[i,j]);
Close(f);
End;
Procedure xuli;
var i,j: longint;
Begin
For i:=1 to m do
begin max[i]:=a[1,j];
For j:=1 to n do
if max[i]<a[i,j] then max[i]:=a[i,j];
end;
End;
Procedure ghikq;
var i,j: longint;
Begin
Assign(f,fo);
Rewrite(f);
For i:=1 to m do
writeln(f,i,#32,max[i]);
close(f);
End;
Begin
doctep;
xuli;
ghikq;
End
-1,0 đ
1,0 đ
1,0 đ
1,0 đ
0,5 đ
0,5 đ
1,0dd
2 Cắm trại
Uses Crt;
Const
fi='CAMTRAI.inp';
fo='CAMTRAI.out';
Nmax=1000+2;
Var
f: text;
6,0 đ
1,0 đ
Trang 2a: array[0 Nmax,0 Nmax] of longint;
m,n,dem: longint;
Procedure doctep;
var i,j: longint;
Begin
Assign(f,fi);
Reset(f);
Readln(f,m,n);
For i:=1 to m do
For j:=1 to n do read(f,a[i,j]);
Close(f);
End;
Function sodep(p,q:longint) : Boolean;
Begin
exit((a[p-1,q] >= 1) and (a[p+1,q] >= 1) and (a[p,q-1] >= 1) and (a[p,q+1] >= 1));
End;
Procedure xuli;
var i,j: longint;
Begin
Assign(f,fo);
Rewrite(f);
dem:=0;
For i:=1 to m do
For j:=1 to n do
IF A[I,J]=0 THEN
if sodep(i,j) then inc(dem);
Write(f,dem);
End;
Procedure ghikq;
Begin
close(f);
End;
Begin
doctep;
xuli;
ghikq;
End
1,0 đ
1,0 đ
1,0 đ 1,0 đ
1,0 đ
3 Ba lô
program bt1;
uses crt;
const fi='balo.inp';
fo='balo.out';
var a,c:array[1 20] of integer;
fx:array[0 20,0 20] of integer;
kt:array[0 100] of 0 1;
n,w,i:integer;
procedure doc;
var i,j:integer;
f:text;
begin
assign(f,fi);reset(f);
readln(f,n,w);
for i:=1 to n do
readln(f,a[i],c[i]);
close(f);
end;
function max(a,b:integer):integer;
begin
if a>b then max:=a
else max:=b;
end;
5,0 đ
1,0 đ
1,0 đ
1,0 đ
Trang 3procedure taobang;
var k,v:integer;
begin
for v:=1 to w do
if v>=a[1] then fx[1,v]:=c[1] else fx[1,v]:=0;
for k:=2 to n do
for v:=1 to w do
if v>=a[k] then
fx[k,v]:=max(fx[k-1,v-a[k]]+c[k], fx[k-1,v])
else
fx[k,v]:=fx[k-1,v];
for k:=1 to n do
begin
for v:=1 to w do write(fx[k,v]:3); writeln;
end;
end;
procedure trabang;
var f:text;
k,v:integer;
begin
assign(f,fo);rewrite(f);
k:=n;
v:=w;
writeln('fx=',fx[k,v]);
repeat
while fx[k,v]=fx[k-1,v] do dec(k);
kt[k]:=1;
v:=v-a[k];
until v=0;
for k:=1 to n do
if kt[k]=1 then writeln(a[k],' ',c[k]);
close(f);
end;
begin
clrscr;
for i:=1 to n do kt[i]:=0;
doc;
taobang;
trabang;
readln;
end
1,0 đ
1,0đ
4 Đồ thị
Uses crt; //Tim duong di ngan nhat tren do thi co huong
Type
cung = record
x,y,w: longint;
end;
Const
fi='Dothi.inp';
fo='Dothi.out';
MMax=1000;
Nmax=1000;
Pmax=1000;
Wmax=Mmax*Pmax;
Var
f:text;
a: array[1 Mmax] of cung;
p: array[1 Pmax] of longint;
vet: array[1 Nmax] of longint;
n,m,s,t: longint;
3,0 đ
1.0 đ
Trang 4Procedure doctep;
Var i,j: longint;
Begin
Assign(f,fi);
reset(f);
readln(f,n,m,s,t);
For i:=1 to M do
with a[i] do readln(f,x,y,w);
close(f);
for j:=1 to N do p[j]:=Wmax;
p[s]:=0;
End;
Function cocung(a: cung): boolean;
var tam:boolean;
Begin
with a do
begin
tam:= (p[x]<Wmax) and (p[y]>p[x]+w);
if tam then
begin
p[y]:=p[x]+w;
vet[y]:=x;
end;
end;
cocung:=tam;
End;
Procedure BellmanFord;
var i,j: longint;
stop: boolean;
Begin
for j:=1 to n- 1 do
begin
stop:=true;
for i:=1 to m do
if cocung(a[i]) then stop:=false;
if stop then break;
end;
End;
Procedure ghikq;
begin
assign(f,fo);
rewrite(f);
if p[t]=WMax then
write(f,'Khong ton tai duong di tu S den t')
else
begin
writeln(f,p[t]);
while s<>t do
begin
write(f,t,'<-');
t:=vet[t];
end;
write(f,s);
end;
close(f);
end;
Begin
doctep;
BellmanFord;
ghikq;
End
1,0 đ
1,0đ
Trang 504 câu Tổng điểm: 20đ