📄 城堡-pascal语言.txt
字号:
{
TASK:castle
LANG:PASCAL
}
program castle;
const
shl2:array[1..4]of integer=(1,2,4,8);
index:array[2..3,1..2] of integer=((-1,0),(0,1));
var
map:array[1..50,1..50,1..4] of boolean;
fill:array[1..50,1..50] of integer;
area:array[1..2500] of integer;
n,m:integer;
procedure init;
var
i,j,k,x:integer;
begin
assign(input,'castle.in');reset(input);
readln(m,n);
fillchar(map,sizeof(map),true);
for i:=1 to n do
begin
for j:=1 to m do
begin
read(x);
for k:=1 to 4 do
if x and shl2[k]<>0 then
map[i,j,k]:=false;
end;
readln;
end;
fillchar(fill,sizeof(fill),0);
fillchar(area,sizeof(area),0);
close(input);
end;
procedure floodfill(x,y,c:integer);
begin
if fill[x,y]=0 then
begin
fill[x,y]:=c;
inc(area[c]);
if map[x,y,1] then floodfill(x,y-1,c);
if map[x,y,2] then floodfill(x-1,y,c);
if map[x,y,3] then floodfill(x,y+1,c);
if map[x,y,4] then floodfill(x+1,y,c);
end;
end;
procedure work;
var
i,j,colour,maxarea,k,x,y,w:integer;
begin
assign(output,'castle.out');rewrite(output);
colour:=0;
maxarea:=0;
for i:=1 to n do
for j:=1 to m do
if fill[i,j]=0 then
begin
inc(colour);
floodfill(i,j,colour);
if area[colour]>maxarea then
maxarea:=area[colour];
end;
writeln(colour);
writeln(maxarea);
maxarea:=0;
for j:=1 to m do
for i:=n downto 1 do
for k:=2 to 3 do
if not map[i,j,k] then
begin
if (i+index[k,1]>0)and(j+index[k,2]<=m)and(fill[i,j]<>fill[i+index[k,1],j+index[k,2]])and (area[fill[i,j]]+area[fill[i+index[k,1],j+index[k,2]]]>maxarea) then
begin
maxarea:=area[fill[i,j]]+area[fill[i+index[k,1],j+index[k,2]]];
x:=i;
y:=j;
w:=k;
end;
end;
writeln(maxarea);
write(x,' ',y,' ');
if w=2 then writeln('N');
if w=3 then writeln('E');
close(output);
end;
begin
init;
work;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -