3450. 【NOIP2013模拟联考3】山峰(summits) (Standard IO)
来源:互联网 发布:贵州浪人网络投诉 编辑:程序博客网 时间:2024/05/29 06:35
Description
作为地质学家的JIH,为了绘制地图进行了野外考察。考察结束,他得到了一张n*m的地面高度地图。为了科学研究,JIH定义了一种山峰叫做d-山峰。一个高度为h地点被称作d-山峰,只有满足从这里出发,在不经过小于等于h-d的地点的前提下无法达到比它更高的地方。JIH正纠结于怎么分礼物,标出d-山峰的任务就交给你了。
Input
第一行n,m,d第二行开始,有一个n*m的矩阵表示地图,用空格隔开。
Output
输出d-山峰的个数。
Sample Input
6 10 20 0 0 0 0 0 0 0 0 00 1 2 1 1 1 1 0 1 00 2 1 2 1 3 1 0 0 00 1 2 1 3 3 1 1 0 00 2 1 2 1 1 1 0 2 00 0 0 0 0 0 0 0 0 0
Sample Output
4
Data Constraint
30% n,m<=10100% 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.
阅读全文
1 2
- 3450. 【NOIP2013模拟联考3】山峰(summits) (Standard IO)
- 【NOIP2013模拟联考3】山峰(summits)
- jzoj. 3450. 【NOIP2013模拟联考3】山峰(summits)
- jzoj3450【NOIP2013模拟联考3】山峰(summits,dfs)
- 【NOIP2013模拟联考3】恭介的法则(rule) (Standard IO)
- 【NOIP2013模拟联考13】线段
- 【NOIP2013模拟联考7】数列
- 【NOIP2013模拟联考5】军训
- 【NOIP2013模拟联考6】选课
- 【NOIP2013模拟联考7】OSU
- JZOJ. 3450 山峰 summits
- JZOJ3455. 【NOIP2013模拟联考3】库特的向量(code)
- JZOJsenior3456.【NOIP2013模拟联考3】恭介的法则(rule)
- 【NOIP2013模拟联考3】恭介的法则(rule)
- JZOJsenior3455.【NOIP2013模拟联考3】库特的向量(code)
- 【NOIP2013模拟联考5】军训(training)
- 【NOIP2013模拟联考6】选课(select)
- 【NOIP2013模拟联考5】军训(training) 题解
- 2017湘潭赛Partial Sum
- BZOJ 1858 序列操作 [线段树]
- 实体类对象状态
- String-API-Review
- 自定义对话框
- 3450. 【NOIP2013模拟联考3】山峰(summits) (Standard IO)
- 对于所有对象都通用的方法
- 洛谷Oj-字串变换-广度优先搜索
- ZOJ Problem Set
- 《算法概论》习题8.3证明
- POJ 1010--STAMPS
- 51nod 1450 闯关游戏
- hadoop2.7.3伪分布式安装
- 65. Valid Number