Seeding--zoj2100
Seeding
Time Limit: 2 Seconds Memory Limit: 65536 KB
It is spring time and farmers have to plant seeds in the field. Tom has a nice field, which is a rectangle with n * m squares. There are big stones in some of the squares.
Tom has a seeding-machine. At the beginning, the machine lies in the top left corner of the field. After the machine finishes one square, Tom drives it into an adjacent square, and continues seeding. In order to protect the machine, Tom will not drive it into a square that contains stones. It is not allowed to drive the machine into a square that been seeded before, either.
Tom wants to seed all the squares that do not contain stones. Is it possible?
Input
The first line of each test case contains two integers n and m that denote the size of the field. (1 < n, m < 7) The next n lines give the field, each of which contains m characters. 'S' is a square with stones, and '.' is a square without stones.
Input is terminated with two 0's. This case is not to be processed.
Output
For each test case, print "YES" if Tom can make it, or "NO" otherwise.
Sample Input
4 4
.S..
.S..
....
....
4 4
....
...S
....
...S
0 0
Sample Output
YES
NO
主要就是深搜!
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m,ds;
char map[][];
int move[][]={,,,-,,,-,};
int visit[][],cot,flag;
void dfs(int x,int y)
{
int next_x,next_y,i;
if(cot==ds)//如果已经找完了所有的点就跳出
{
flag=;//设置一个开关
return;
}
for(i=;i<;i++)
{
next_x=x+move[i][];
next_y=y+move[i][];//往四个方向移动
if(next_x>=&&next_x<n&&next_y>=&&next_y<m)//在图的范围内
{
if(!visit[next_x][next_y]&&map[next_x][next_y]!='S') //没被访问过,这个点还不能是S
{
cot++;//访问一次就加一次
visit[next_x][next_y]=;//标记为走过
dfs(next_x,next_y);//进入下一层
visit[next_x][next_y]=;//取消标记
cot--;//跳出一次就减一次
}
}
}
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m),n||m)
{
getchar();
cot=;
ds=;
flag=;
for(i=;i<n;i++)
{
for(j=;j<m;j++)
{
visit[i][j]=;
scanf("%c",&map[i][j]);
if(map[i][j]=='.')
ds++;//记录点的个数
}
getchar();
}
visit[][]=;//访问过就标记为1
cot++;//先加一次
dfs(,);//从0,0点开始访问
//printf("%d\n",ds);
if(flag)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
Seeding--zoj2100的更多相关文章
- zoj 2100 Seeding
Seeding Time Limit: 2 Seconds Memory Limit: 65536 KB It is spring time and farmers have to plan ...
- Seeding(dfs)
Seeding Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- Oracle Warehouse Builder(OWB) 安装报seeding owbsys错误的解决
今天在RHEL6.4上安装Oracle Warehouse Builder 11.2时在最后一步报错,打开日志查看有例如以下信息: main.TaskScheduler timer[5]2014052 ...
- JAVA UUID 生成
UUID是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成UUID的API.UUID按照开放软件基金会(OSF)制定的标准计算,用到了以太网卡地址.纳秒级时间.芯 ...
- 超像素经典算法SLIC的代码的深度优化和分析。
现在这个社会发展的太快,到处都充斥着各种各样的资源,各种开源的平台,如github,codeproject,pudn等等,加上一些大型的官方的开源软件,基本上能找到各个类型的代码.很多初创业的老板可能 ...
- 使用wget命令时发生错误
用的是centos6.5, 当我使用命今 sudo wget https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz 下载个cmake的包时, 发生了这样的错误 ...
- theano学习
import numpy import theano.tensor as T from theano import function x = T.dscalar('x') y = T.dscalar( ...
- Azure SQL Database Active Geo-Replication简介
笔者在<迁移SQL Server 数据库到 Azure SQL 实战>一文中,介绍了如何把一个本地版的 SQL Server 数据库迁移到 Azure SQL Database.迁移虽然顺 ...
- Code First :使用Entity. Framework编程(6) ----转发 收藏
Chapter6 Controlling Database Location,Creation Process, and Seed Data 第6章 控制数据库位置,创建过程和种子数据 In prev ...
- ASP.NET Identity系列教程(目录)
$(document).ready(function(){ $("#hide").click(function(){ $(".en").hide(); }); ...
随机推荐
- VM11里安装ubuntukylin-16.04-desktop-amd64遇到问题
一.ubuntu linux的地址 http://www.ubuntu-china.cn/ 这个地址是中国站,点击下载菜单后,有两个版本,一个是ubuntu,一个是kylin.后者是专门加了中文程序的 ...
- shell date格式化输出
1- echo `date "+%Y-%m-%d %H:%M:%S"` 2014-11-13 15:06:26 2- echo `date "+%y-%m-%d %H ...
- [C++程序设计]变量的存储类别
全局变量全部存放在静态存储区中,在程序开始执行时给全局变量分配存储单元,程序执行完毕就释放这些空间.在程序执行过程中它们占据固定的存储单元,而不是动态地进行分配和释放. 在动态存储区中存放以下数据: ...
- mysql之主从复制
原理--> 在数据库层面,复制语句或者行,因为在数据库层面,故只有主服务器生成,并放到二进制日志里面,才能复制给从服务器. 原理--> mysql的主从复制基于异步,主要有三个进程执行,分 ...
- 关于python的面向对象编程
先写上代码,有代码才好理解: #filename:classdemo.py class test: '''just person''' a=1 b=2 c=0 def __init__(self): ...
- 关于C语言中的强符号、弱符号、强引用和弱引用的一些陋见,欢迎指正
首先我表示很悲剧,在看<程序员的自我修养--链接.装载与库>之前我竟不知道C有强符号.弱符号.强引用和弱引用.在看到3.5.5节弱符号和强符号时,我感觉有些困惑,所以写下此篇,希望能和同样 ...
- CSS开发经验
1.尽量用class来定义样式.尽量少使用 .div1 ul li{}这样的样式下去,因为如果li里面还有<div><ul><li>这些元素的话会造成干扰,应该给 ...
- scheme递归
主要参考: http://www.shido.info/lisp/scheme7_e.html Function fact that calculates factorials. (define (f ...
- UESTC_Big Brother 2015 UESTC Training for Graph Theory<Problem G>
G - Big Brother Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) ...
- Remove Nth Node From End of List 解答
Question Given a linked list, remove the nth node from the end of list and return its head. For exam ...