2017-07-08【NOIP提高组】模拟赛B组-山峰(summits)-题解
来源:互联网 发布:中控考勤机数据修改 编辑:程序博客网 时间:2024/05/22 07:42
原题:
http://172.16.0.132/senior/#contest/show/2041/2
题目描述:
作为地质学家的JIH,为了绘制地图进行了野外考察。考察结束,他得到了一张n*m的地面高度地图。为了科学研究,JIH定义了一种山峰叫做d-山峰。一个高度为h地点被称作d-山峰,只有满足从这里出发,在不经过小于等于h-d的地点的前提下无法达到比它更高的地方。JIH正纠结于怎么分礼物,标出d-山峰的任务就交给你了。
输入:
第一行n,m,d
第二行开始,有一个n*m的矩阵表示地图,用空格隔开。
输出:
输出d-山峰的个数。
样例输入:
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
样例输出:
4
数据范围限制:
30% n,m<=10
100% n,m<=500
提示:
分析:
正难则反,用总共的点-不合法的点,即为合法点。
枚举每一个点,暴力跑答案判断,用记忆化优化,如果发现当前点的高度>h-d,并是没有遍历过的就exit(true) else exit(false);
每次找到不合法的点,就dec(ans);
如果跑的点数>n*m的话就直接exit掉了。
暴力可以宽搜,也可以深搜。
实现:
uses math;const u:array[1..4,1..2]of longint=((0,1),(1,0),(0,-1),(-1,0));var ans,n,m,d,i,j,maxn:longint; a,f:array[0..501,0..501]of longint; bz:array[0..501,0..501]of boolean;function dg(x,y,h,sum,tot:longint):boolean;var i,xx,yy:longint;begin f[x,y]:=sum; if a[x,y]>h then begin dec(ans); exit(true); end; if (a[x,y]=h)and(bz[x,y]) then begin dec(ans); exit(true); end; if tot>n*m then exit(false); for i:=1 to 4 do begin xx:=x+u[i,1]; yy:=y+u[i,2]; if (xx>0)and(xx<=n)and(yy>0)and(yy<=m) then if (f[xx,yy]<>sum)and(a[xx,yy]>h-d)and(dg(xx,yy,h,sum,tot+1)) then exit(true); end; exit(false);end;begin readln(n,m,d); for i:=1 to n do for j:=1 to m do begin read(a[i,j]); maxn:=max(a[i,j],maxn); end; ans:=n*m; for i:=1 to n do for j:=1 to m do if a[i,j]<>maxn then bz[i,j]:=dg(i,j,a[i,j],i*m+j,0); writeln(ans);end.
阅读全文
2 0
- 2017-07-08【NOIP提高组】模拟赛B组-山峰(summits)-题解
- 2017-07-08【NOIP提高组】模拟赛B组-连通块(connect)-题解
- 2017.10.07【NOIP提高组】模拟赛B组 偷懒的西西 题解
- 2017.10.07【NOIP提高组】模拟赛B组 瑰丽华尔兹 题解
- 2017.10.07【NOIP提高组】模拟赛B组 Heatwave 题解
- 2016.10.07【初中部 NOIP提高组 】模拟赛C题解
- 计蒜客 2017 NOIP 提高组模拟赛(一)题解
- 2017.1.15【初中部 NOIP提高组】模拟赛B组 寻找羔羊(agnus) 题解
- 2017.1.15【初中部 NOIP提高组】模拟赛B组 重复字符串(powerstr) 题解
- 2017.1.15【初中部 NOIP提高组】模拟赛B组 七天使的通讯(angelus) 题解
- 2017.10.06【NOIP提高组】模拟赛B组 整除 题解
- 2017.10.06【NOIP提高组】模拟赛B组 新壳栈 题解
- 2017.10.06【NOIP提高组】模拟赛B组 青蛙 题解
- 2017.07.07【NOIP提高组】模拟赛B组
- 2017.07.07【NOIP提高组】模拟赛B组小结
- 2017.08.07【NOIP提高组】模拟赛B组
- 2017.07.08【NOIP提高组】模拟赛B组
- 2017.07.08【NOIP提高组】模拟赛B组小结
- TCP的三次握手和四次挥手详解
- 2017-07-08【NOIP-普及组】模拟赛C组-sum-题解
- 2017-07-08【NOIP提高组】模拟赛B组-连通块(connect)-题解
- ToBase64String方法
- 理解Linux系统负荷
- 2017-07-08【NOIP提高组】模拟赛B组-山峰(summits)-题解
- suse系统解决ssh登录慢的办法
- Win7风格的MFC
- 算法系列——Reverse Linked List
- WooCommerce——修改“Related Products“文字
- 解读Secondary NameNode的功能
- Fragment && Activity生命周期
- java初学者的浅谈(4)
- hihoCoder1080-更为复杂的买卖房屋姿势