比赛 暑假培训B班二测 评测结果 EEEEEEEE
题目名称 劣质的草 最终得分 0
用户昵称 RT 运行时间 0.946 s
代码语言 Pascal 内存使用 7.81 MiB
提交时间 2012-07-22 10:38:24
显示代码纯文本
Program RT;
var
m,n,i,j,k,p,q,max,js:longint;
a:array [0..1000,0..1000] of int64;
//----$_$---O_O--!------@_@-----^_^-------//
function run(i,j:longint):longint;
var
p,q:longint;
begin
if a[i-1,j]<>0 then begin
if a[i-1,j]<>-1 then js:=js+1;
a[i-1,j]:=-1;
i:=i-1;
run(i,j);
end;

if a[i,j+1]<>0 then begin
if a[i,j+1]<>-1 then js:=js+1;
a[i,j+1]:=-1;
j:=j+1;
run(i,j);
end;

if a[i,j-1]<>0 then begin
if a[i,j-1]<>-1 then js:=js+1;
a[i,j-1]:=-1;
j:=j-1;
run(i,j);
end;

if a[i+1,j]<>0 then begin
if a[i+1,j]<>-1 then js:=js+1;
a[i+1,j]:=-1;
i:=i+1;
run(i,j);
end;

if a[i+1,j+1]<>0 then begin
if a[i+1,j+1]<>-1 then js:=js+1;
a[i+1,j+1]:=-1;
i:=i+1;
j:=j+1;
run(i,j);
end;

if a[i-1,j-1]<>0 then begin
if a[i-1,j-1]<>-1 then js:=js+1;
a[i-1,j-1]:=-1;
i:=i-1;
j:=j-1;
run(i,j);
end else begin if a[i-1,j]=-1 then
i:=i+1;
if  a[i,j+1]=-1 then j:=j-1;
if a[i,j-1]=-1 then  j:=j+1;
if a[i+1,j]=-1 then i:=i-1;
if a[i+1,j+1]=-1 then
begin
i:=i-1;
j:=j-1;
end;
if a[i-1,j-1]=-1 then
begin
i:=i+1;
j:=j+1;
end;
end;

if js<>0 then max:=max+1;
end;
//---^_^--#_@---O_O--!-----$_$---*_*-------//

begin
//-------------------------------------//
assign(input,'badgras.in');     //--O_O||
reset(input);                   //--$_$||
assign(output,'badgras.out');   //--$_$||
rewrite(output);                //--O_O||
//-------------------------------------//
read(m,n);
for i:=1 to m do
 for j:=1 to n do
 read(a[i,j]);
for i:=1 to m do
 for j:=1 to n do
if (a[i,j]>0) then
begin
js:=js+1;
a[i,j]:=-1;
run(i,j);
end;
write(max);
close(input);
close(output);
end.