您的位置:首页 > 其它

3450. 【NOIP2013模拟联考3】山峰(summits) (Standard IO)

2017-07-08 21:00 288 查看

Description

作为地质学家的JIH,为了绘制地图进行了野外考察。考察结束,他得到了一张n*m的地面高度地图。为了科学研究,JIH定义了一种山峰叫做d-山峰。一个高度为h地点被称作d-山峰,只有满足从这里出发,在不经过小于等于h-d的地点的前提下无法达到比它更高的地方。JIH正纠结于怎么分礼物,标出d-山峰的任务就交给你了。


Input

第一行n,m,d
第二行开始,有一个n*m的矩阵表示地图,用空格隔开。


Output

输出d-山峰的个数。


Sample Input

6 10 2
0 0 0 0 0 0 0 0 0 0
0 1 2 1 1 1 1 0 1 0
0 2 1 2 1 3 1 0 0 0
0 1 2 1 3 3 1 1 0 0
0 2 1 2 1 1 1 0 2 0
0 0 0 0 0 0 0 0 0 0


Sample Output

4


Data Constraint

30% n,m<=10
100% n,m<=500


###思路

一开始只想搜索要点分,后来优化一下就过了。
对于每个点dfs一次,判断是否为山峰,而对于走过的点如果清空就会很耗时间,所以第一次dfs时走过的点记为1,第二次为2,以此类推就不用清空数组了。


var
a,b:array[0..600,0..600] of longint;
n,m,d,x,h:longint;
f:boolean;
procedure dfs(y,z,s:longint);
begin
b[y,z]:=s;
if (y<=0)or(z<=0)or(y>n)or(z>m) then exit;
if a[y,z]>h then f:=false;
if not f then exit;
if (a[y,z-1]>h-d)and(b[y,z-1]<>s)and(f) then
dfs(y,z-1,s);
if (a[y,z+1]>h-d)and(b[y,z+1]<>s)and(f) then
dfs(y,z+1,s);
if (a[y-1,z]>h-d)and(b[y-1,z]<>s)and(f) then
dfs(y-1,z,s);
if (a[y+1,z]>h-d)and(b[y+1,z]<>s)and(f) then
dfs(y+1,z,s);
end;
var
i,j,ans:longint;
begin
readln(n,m,d);
for i:=1 to n do
for j:=1 to m do
read(a[i,j]);
x:=0;
ans:=0;
for i:=1 to n do
begin
for j:=1 to m do
begin
inc(x);
h:=a[i,j];
f:=true;
dfs(i,j,x);
if f then inc(ans);
end;
end;
writeln(ans);
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: