NOJ——1559Jump to the Top of Mountain(简单暴力DFS+渣渣代码)
来源:互联网 发布:2017淘宝可以买彩票吗 编辑:程序博客网 时间:2024/05/16 18:32
[1559] Jump to the Top of Mountain
Have you played a game named Minecraft?
In the game, there is a thing alloy you can not destroy, and its shape is a 1*1*1 area cube. I can only jump 1 meter at vertical height, it means I can jump from x meters height to y meters height when y is not more than x+1.
Now, there is a rectangle field of m*n areas, each area is a positive interger X, X means the number of alloy in this area. You can only jump to four adjacent areas(up, down, left and right).
At the beginning, you are at out of the rectangle field, and the height is 0 out of the rectangle field.
Can you help me? I only want to know if I can jump to the peak of field?
In the game, there is a thing alloy you can not destroy, and its shape is a 1*1*1 area cube. I can only jump 1 meter at vertical height, it means I can jump from x meters height to y meters height when y is not more than x+1.
Now, there is a rectangle field of m*n areas, each area is a positive interger X, X means the number of alloy in this area. You can only jump to four adjacent areas(up, down, left and right).
At the beginning, you are at out of the rectangle field, and the height is 0 out of the rectangle field.
Can you help me? I only want to know if I can jump to the peak of field?
Input ends of EOF.
First line contains two positive integers m and n(3 <= m, n <= 100).
Then m lines, each line contains n intergers X(0 <= X <= 10000).
First line contains two positive integers m and n(3 <= m, n <= 100).
Then m lines, each line contains n intergers X(0 <= X <= 10000).
If I can jump to the peak, output "YES", or output "NO".
5 52 2 1 2 22 2 2 2 22 2 3 2 22 2 2 2 22 2 2 2 23 32 1 22 0 11 1 34 41 1 1 11 3 1 21 1 1 31 1 1 44 41 2 3 48 7 6 59 10 11 1216 15 14 13
YESNOYESYES
基本没写过几道搜索。由于从边缘进入,枚举边缘所有格子进行搜索即可,如果认真读题肯定可以知道能向低处走...以为只能平地或高一格还赏了一个WA。蛋疼
代码非常搓+渣:
#include<iostream>#include<algorithm>#include<cstdlib>#include<sstream>#include<cstring>#include<cstdio>#include<string>#include<deque>#include<stack>#include<cmath>#include<queue>#include<set>#include<map>using namespace std;typedef long long LL;#define INF 0x3f3f3f3fint pos[110][110];int vis[110][110];int flag=0;int tall;int n,m;void look(const int &x,const int &y,const int &pre){if(x<0||y<0||x>=n||y>=m||vis[x][y]==1)//边界+是否访问过判断return;vis[x][y]=1;//标记访问if(pos[x][y]-pre<=1){if(pos[x][y]==tall){flag=1;puts("YES");return;}look(x+1,y,pos[x][y]);if(!flag)look(x-1,y,pos[x][y]);if(!flag)look(x,y+1,pos[x][y]);if(!flag)look(x,y-1,pos[x][y]);}else{vis[x][y]=0;//路不通,不算访问过。return;}}int main(void){int i,j;while (~scanf("%d%d",&n,&m)){memset(pos,0,sizeof(pos));tall=-1;flag=0;for (i=0; i<n; i++){for (j=0; j<m; j++){scanf("%d",&pos[i][j]);tall=max(tall,pos[i][j]);}}if(tall==0){puts("NO");continue;}for (j=0; j<m; j++){if(pos[0][j]==1){memset(vis,0,sizeof(vis));look(0,j,0);}if(flag)break;}if(!flag){for (j=0; j<m; j++){if(pos[n-1][j]==1){memset(vis,0,sizeof(vis));look(n-1,j,0);}if(flag)break;}}if(!flag){for (i=0; i<n; i++){if(pos[i][0]==1){memset(vis,0,sizeof(vis));look(i,0,0);}if(flag)break;}}if(!flag){for (i=0; i<n; i++){if(pos[i][m-1]==1){memset(vis,0,sizeof(vis));look(i,m-1,0);}if(flag)break;}}if(!flag)puts("NO");}return 0;}
0 0
- NOJ——1559Jump to the Top of Mountain(简单暴力DFS+渣渣代码)
- [noj 1559] Jump to the Top of Mountain
- Mountain Walking ——dfs
- UVALive - 6800 The Mountain of Gold?(Bellman-ford找负权回路,dfs)
- HDU 1010 Tempter of the Bone(DFS+暴力+标记)
- NOJ——1274The battle of Red Cliff(并查集按秩合并)
- NOJ 1139 The Gluttonous Rat——【BFS, DFS, 队列与栈之间不能说的秘密】
- UVALive 6800 The Mountain of Gold (bellman_ford判负环)
- UVAlive 6800 The Mountain of Gold?(负环判断)
- hdu1010——Tempter of the Bone(DFS+剪枝)
- The number of ponds——DFS
- Move The Taskbar to the Top of Desktop
- NOJ 1317——Exercise of Sort
- NOJ——[1143] Irrigation of Farmland
- uvalive 6800 - The Mountain of Gold? 判负环
- Started to climb the Akka mountain
- Top of The World
- Top of The World
- POJ——3070Fibonacci(矩阵快速幂)
- factorial using c
- HDU——1005Number Sequence(模版题 二维矩阵快速幂+操作符重载)
- HDU——4291A Short problem(矩阵快速幂+循环节)
- 当有人提给我一个bug...
- NOJ——1559Jump to the Top of Mountain(简单暴力DFS+渣渣代码)
- 校赛——1096Is The Same?(KMP或字符串的最小、大表示法)
- Maven Java EE Configuration Problem
- 关于系统重装的一件小事
- MAVEN在eclipse(kepler)里的安装配置
- 动态代理实现
- 大神是如何装逼的 之 vim插件使用taglist和nerdtree
- google官方架构MVP解析与实战-(从零开始搭建android框架系列(3))
- (OK) Creates Docker-based Virtual PC containers for use inside GNS3 as end hosts.