📄 skiarea.pas
字号:
{
PROB:skiarea
LANG:PASCAL
}
program skiarea;
const
maxsize=500;
dx:array[1..4]of shortint=(0,0,-1,1);
dy:array[1..4]of shortint=(-1,1,0,0);
var
map:array[1..maxsize,1..maxsize]of integer;
v:array[1..maxsize,1..maxsize]of boolean;
qx,qy:array[1..sqr(maxsize)]of word;
m,n,i,j,hill,valley,f,r,d,p,q:longint;
ishill,isvalley:boolean;
procedure floodfill(x,y:word);
begin
ishill:=true;isvalley:=true;
f:=0;r:=1;qx[1]:=x;qy[1]:=y;v[x,y]:=true;
repeat
inc(f);x:=qx[f];y:=qy[f];
for d:=1 to 4 do begin
p:=x+dx[d];q:=y+dy[d];
if (p>0) and (p<=m) and (q>0) and (q<=n) then
if map[x,y]>map[p,q] then
isvalley:=false
else if map[x,y]<map[p,q] then
ishill:=false
else if not v[p,q] then begin
inc(r);qx[r]:=p;qy[r]:=q;v[p,q]:=true;
end;
end;
until f=r;
if ishill<>isvalley then
if ishill then inc(hill) else inc(valley);
end;
begin
assign(input,'skiarea.in');reset(input);
assign(output,'skiarea.out');rewrite(output);
read(n,m);
for i:=1 to m do
for j:=1 to n do
read(map[i,j]);
fillchar(v,sizeof(v),0);
hill:=0;valley:=0;
for i:=1 to m do
for j:=1 to n do
if not v[i,j] then
floodfill(i,j);
if hill>valley then writeln(hill) else writeln(valley);
close(input);close(output);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -