NOJ——1559Jump to the Top of Mountain(简单暴力DFS+渣渣代码)
[1559] Jump to the Top of Mountain
- 时间限制: 1000 ms 内存限制: 65535 K
- 问题描述
- 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? - 输入
- 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). - 输出
- If I can jump to the peak, output "YES", or output "NO".
- 样例输入
5 5
2 2 1 2 2
2 2 2 2 2
2 2 3 2 2
2 2 2 2 2
2 2 2 2 2
3 3
2 1 2
2 0 1
1 1 3
4 4
1 1 1 1
1 3 1 2
1 1 1 3
1 1 1 4
4 4
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13- 样例输出
YES
NO
YES
YES
基本没写过几道搜索。由于从边缘进入,枚举边缘所有格子进行搜索即可,如果认真读题肯定可以知道能向低处走...以为只能平地或高一格还赏了一个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 0x3f3f3f3f
int 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;
}
NOJ——1559Jump to the Top of Mountain(简单暴力DFS+渣渣代码)的更多相关文章
- 经验分享:10个简单实用的 jQuery 代码片段
尽管各种 JavaScirpt 框架和库层出不穷,jQuery 仍然是 Web 前端开发中最常用的工具库.今天,向大家分享我觉得在网站开发中10个简单实用的 jQuery 代码片段. 您可能感兴趣的相 ...
- 10个简单实用的 jQuery 代码片段
尽管各种 JavaScirpt 框架和库层出不穷,jQuery 仍然是 Web 前端开发中最常用的工具库. 今天,向大家分享我觉得在网站开发中10个简单实用的 jQuery 代码片段. 1.平滑滚动到 ...
- 简单实用的HTML代码
简单实用的HTML代码 一.HTML各种命令的代码: 1.文本标签(命令) <pre></pre> 创建预格式化文本 <h1></h1> 创建最大的标题 ...
- Hadoop基础-MapReduce入门篇之编写简单的Wordcount测试代码
Hadoop基础-MapReduce入门篇之编写简单的Wordcount测试代码 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本文主要是记录一写我在学习MapReduce时的一些 ...
- [.net 面向对象程序设计进阶] (22) 团队开发利器(一)简单易用的代码管理工具VSS
[.net 面向对象程序设计进阶] (22) 团队开发利器(一)简单易用的代码管理工具VSS 本篇要点:在进阶篇快要结束的时候说说源代码管理器,我们的开发,不是一个人可以完成的事,团队协作很重要,而且 ...
- 暴力求解——UVA 572(简单的dfs)
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- PHP分页初探 一个最简单的PHP分页代码的简单实现
PHP分页代码在各种程序开发中都是必须要用到的,在网站开发中更是必选的一项. 要想写出分页代码,首先你要理解SQL查询语句:select * from goods limit 2,7.PHP分页代码核 ...
- POJ 3256 (简单的DFS)
//题意是 K N, M; //有K个牛 N个牧场,M条路 ,有向的 //把K个牛放到任意的n个不同牧场中,问所有牛都可以到达的牧场数的总和 //这是一道简单的DFS题 //k 100 //n 1 ...
- 用简单的反射优化代码(动态web项目)
在动态web项目中,没有使用框架时,只是简单的jsp访问servlet实现增删改查, 无论是哪个方法都需要经过Servlet中的doGet()方法或doPost()方法,我们可以在链接中附带参数进行区 ...
随机推荐
- 11gR2 新特性: Rebootless Restart
众所周知,当集群出现问题时,例如某个节点丢失网络心跳,或者不能够访问表决盘,或者节点出现了严重的性能问题等,CRS会选择将某个节点的OS 重启,以便保证集群的一致性.当然,大部分的重启都是由CRS的核 ...
- Stream great concerts wherever you are
This time of year, we take stock of what we're thankful for — and above all else, we’re thankful for ...
- js函数节流和函数防抖
概念解释 函数节流: 频繁触发,但只在特定的时间内才执行一次代码 函数防抖: 频繁触发,但只在特定的时间内没有触发执行条件才执行一次代码 函数节流 函数节流应用的实际场景,多数在监听页面元素滚动事件的 ...
- 【线程池】ExecutorService与quartz搭配出现的问题
问题描述: 使用quartz定时推送微信公众号模板消息,一分钟推送一次,定时器里面使用了一个ExecutorService线程池,大小为5个. 批量获取数据之后,全部数据都被分配到n/5的线程池里面等 ...
- token验证机制
最近在vue-cli项目实现登录的过程中用到了token验证,在此总结如下 1. 登录时,客户端通过用户名与密码请求登录 2. 服务端收到请求去验证用户名与密码 3. 验证通过,服务端会签发一个Tok ...
- json.dumps ensure_ascii 方法
在使用json.dumps时要注意一个问题 import json print (json.dumps('中国')) "\u4e2d\u56fd" 输出的会是 '中国' 中 ...
- python之序列化
什么叫序列化? 序列化是指把内存里的数据类型转变成字符串,以使其能存储到硬盘或通过网络传输到远程,因为硬盘或网络传输时只能接受bytes. 把字符转换成内存数据类型,叫反序列化. 为什么要序列化? 你 ...
- XML映射文件中关系映射
映射(多)对一.(一)对一的关联关系 1).使用列的别名 ①.若不关联数据表,则可以得到关联对象的id属性 ②.若还希望得到关联对象的其它属性.则必须关联其它的数据表 1.创建表: 员工表: DROP ...
- printk的使用技巧
在 linux/kernel.h 中有相应的宏对应. #define KERN_EMERG "<0>" /* system is unusable */#d ...
- poj3617 best cow line(贪心题)
Best Cow Line Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32687 Accepted: 8660 De ...