比赛 20140714下午练习 评测结果 AAAAAAAA
题目名称 城堡 最终得分 100
用户昵称 甘罗 运行时间 0.004 s
代码语言 Pascal 内存使用 0.20 MiB
提交时间 2014-07-14 14:40:46
显示代码纯文本
program castle;
const
d:array[1..4]of longint=(1,2,4,8);
dx:array[1..4]of longint=(0,-1,0,1);
dy:array[1..4]of longint=(-1,0,1,0);
var
h:array[0..51,0..51,1..4]of boolean;
v:array[0..51,0..51]of longint;
m,n,a,b,c,maxs,cover,total:longint;
size:array[0..3000]of longint;
procedure init;
begin
assign(input,'castle.in');
assign(output,'castle.out');
reset(input);
rewrite(output);
end;
procedure terminate;
begin
close(input);
close(output);
halt;
end;
procedure readdata;
var
k,num,i,j:longint;
begin
fillchar(h,sizeof(h),false);
readln(m,n);
for i:=1 to n do
begin
for j:=1 to m do
begin
read(num);
for k:=4 downto 1 do
begin
if (num>=d[k]) then
begin
dec(num,d[k]);
h[i,j,k]:=true;
end;
end;
end;
readln;
end;
end;
procedure dfs(i,j:longint);
var
x,y,k:longint;
begin
v[i,j]:=total;
for k:=4 downto 1 do
begin
x:=i+dx[k];
y:=j+dy[k];
if (x>0) and (x<=n) and (y>0) and (y<=m)
then
if (not h[i,j,k])
and (v[x,y]=0) then
begin
inc(size[total]);
dfs(x,y);
end;
end;
end;
procedure main;
var
x,y,k,i,j:longint;
begin
fillchar(v,sizeof(v),0);
total:=0;
maxs:=0;
for i:=1 to n do
for j:=1 to m do
if (v[i,j]=0) then
begin
inc(total);
size[total]:=1;
dfs(i,j);
if size[total]>maxs then maxs:=size[total];
end;
writeln(total);
writeln(maxs);
{for i:=1 to n do
begin
for j:=1 to m do
write(v[i,j]);
writeln;
end;}
cover:=0;
for j:=1 to m do
for i:=n downto 1 do
for k:=2 to 3 do
begin
x:=i+dx[k];
y:=j+dy[k];
if (x>0) and (y<=m) and (v[i,j]<>v[x,y]) then
if size[v[i,j]]+size[v[x,y]]>cover then
begin
cover:=size[v[i,j]]+size[v[x,y]];
a:=i;
b:=j;
c:=k;
end;
end;
writeln(cover);
write(a,' ',b,' ');
if c=2 then writeln('N');
if c=3 then writeln('E');
end;
begin
init;
readdata;
main;
terminate;
end.