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.
相关文章推荐
- jzoj. 3450. 【NOIP2013模拟联考3】山峰(summits)
- jzoj3450【NOIP2013模拟联考3】山峰(summits,dfs)
- 【NOIP2013模拟联考3】恭介的法则(rule) (Standard IO)
- 【NOIP2013模拟联考3】山峰(summits)
- jzoj 3467. 【NOIP2013模拟联考7】最长上升子序列(lis) dfs+lis+手工栈
- 【NOIP2011模拟9.3】旅行 (Standard IO)
- 2558. 【NOIP2011模拟9.9】过河问题 (Standard IO)
- 3067. 【NOIP2012模拟10.29晚】密码盘 (Standard IO)
- JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)
- 【NOIP2013模拟联考7】数列
- 【NOIP2014模拟】逻辑的连通性 (Standard IO)
- [jzoj]3472. 【NOIP2013模拟联考8】匹配(match)(AC自动机+DP)
- 3472. 【NOIP2013模拟联考8】匹配(match)
- 2548. 【NOIP2011模拟9.4】最大正方形 (Standard IO)
- [jzoj]3479. 【NOIP2013模拟联考9】工作安排(work)
- JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)
- 【NOIP2014模拟11.2A组】国色天香 (Standard IO)
- 高中OJ3494. 【NOIP2013模拟联考13】线段(segment)
- 【NOIP2011模拟9.1】方格取数 (Standard IO)
- [jzoj]3480. 【NOIP2013模拟联考9】阿Q的停车场(park)(线段树+堆)