• [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+渣渣代码)的更多相关文章

  1. 经验分享:10个简单实用的 jQuery 代码片段

    尽管各种 JavaScirpt 框架和库层出不穷,jQuery 仍然是 Web 前端开发中最常用的工具库.今天,向大家分享我觉得在网站开发中10个简单实用的 jQuery 代码片段. 您可能感兴趣的相 ...

  2. 10个简单实用的 jQuery 代码片段

    尽管各种 JavaScirpt 框架和库层出不穷,jQuery 仍然是 Web 前端开发中最常用的工具库. 今天,向大家分享我觉得在网站开发中10个简单实用的 jQuery 代码片段. 1.平滑滚动到 ...

  3. 简单实用的HTML代码

    简单实用的HTML代码 一.HTML各种命令的代码: 1.文本标签(命令) <pre></pre> 创建预格式化文本 <h1></h1> 创建最大的标题 ...

  4. Hadoop基础-MapReduce入门篇之编写简单的Wordcount测试代码

    Hadoop基础-MapReduce入门篇之编写简单的Wordcount测试代码 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本文主要是记录一写我在学习MapReduce时的一些 ...

  5. [.net 面向对象程序设计进阶] (22) 团队开发利器(一)简单易用的代码管理工具VSS

    [.net 面向对象程序设计进阶] (22) 团队开发利器(一)简单易用的代码管理工具VSS 本篇要点:在进阶篇快要结束的时候说说源代码管理器,我们的开发,不是一个人可以完成的事,团队协作很重要,而且 ...

  6. 暴力求解——UVA 572(简单的dfs)

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  7. PHP分页初探 一个最简单的PHP分页代码的简单实现

    PHP分页代码在各种程序开发中都是必须要用到的,在网站开发中更是必选的一项. 要想写出分页代码,首先你要理解SQL查询语句:select * from goods limit 2,7.PHP分页代码核 ...

  8. POJ 3256 (简单的DFS)

    //题意是 K N, M; //有K个牛 N个牧场,M条路 ,有向的  //把K个牛放到任意的n个不同牧场中,问所有牛都可以到达的牧场数的总和  //这是一道简单的DFS题 //k 100 //n 1 ...

  9. 用简单的反射优化代码(动态web项目)

    在动态web项目中,没有使用框架时,只是简单的jsp访问servlet实现增删改查, 无论是哪个方法都需要经过Servlet中的doGet()方法或doPost()方法,我们可以在链接中附带参数进行区 ...

随机推荐

  1. FMDB浅析(思想)

    http://www.cnblogs.com/OTgiraffe/p/5931800.html 一.FMDB介绍 FMDB是一种第三方的开源库,FMDB就是对SQLite的API进行了封装,加上了面向 ...

  2. idea存留

    1.导师匿名评价系统 类似看准网 2.在线降重软件 基于翻译api,或者后期写算法 在线查重导流 公众号: e搜罗

  3. 分类回归树(CART)

    概要 本部分介绍 CART,是一种非常重要的机器学习算法.   基本原理   CART 全称为 Classification And Regression Trees,即分类回归树.顾名思义,该算法既 ...

  4. 总结一下自己脑海里的JavaScript吧(一)--DOM模型

    今天是2019年6月25日,闲来无事,写一篇文章来看看自己脑袋里装了多少JavaScript知识! 这儿就第一章: 说起JavaScript,它是什么?后端脚本语言?前端编程语言?还是在网站浏览器上运 ...

  5. centos Chrony设置服务器集群同步时间

    Chrony是一个开源的自由软件,像CentOS 7或基于RHEL 7操作系统,已经是默认服务,默认配置文件在 /etc/chrony.conf 它能保持系统时间与时间服务器(NTP)同步,让时间始终 ...

  6. SC || Chapter7 健壮性和正确性

    finally中语句不论有无异常都执行 若子类重写了父类方法,父类方法没有抛出异常,子类应自己处理全部异常而不再传播:子类从父类继承的方法不能增加或更改异常 判断checked和unchecked: ...

  7. 题解 P5051 【[COCI2017-2018#7] Timovi】

    看到这道题目,数据范围,心凉了一大截 这是没开O2的 而这是开了O2的 emm……本蒟蒻也无言以对呀 好了,回归正题,看到题目的标签,高性能,自然而然地想到了快读 相信做这题的大佬们一定知道吧! 快读 ...

  8. 配置centos7解决 docker Failed to get D-Bus connection 报错

    在centos7的容器里面出现了一个BUG,就是serveice启动服务的时候出现报错,不能用service启动服务.[root@e13c3d3802d0 /]# service httpd star ...

  9. matplotlib绘图(三)

    matplotlib中2D图形的绘制 直方图 直方图的参数只有一个x,不像条形图需要传入x,y 直方图作用:是统计x在某个区间上出现的次数 直方图是条形图的一种形式 hist()的参数: #bins ...

  10. Vue基础指令集锦

    v-model双向绑定数据 <input type="text" v-model="msg"> {{msg}} ###v-on 事件 <div ...