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

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.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值