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(); }); ...
随机推荐
- img元素高度多出来的几像素
HTML: <div class="test"><img src="body2.jpg" alt=""></d ...
- ZendFramework 环境部署
查看源码 int_autoloader.php 文件中,发现应用了一个 AutoloaderFactory 的命名空间,路径写得是相对路径,所以需要在 php.ini 中定义一个 inclde_pat ...
- PyQt4.11.3(python3.4+QT4)ui文件生成py文件
最近开始接触学习Python,所以想用QT弄个窗体程序出来玩玩,环境是Python3.4.2.PyQt4.11.3-Py3.4.Win7.用PyQt自带的Designer设计出一个窗体ui文件后,需要 ...
- information_schema.collation_character_set_applicability 学习
字符集和排序规则之间是不可以随便搭配的.如果你想知道一个字符集它所搭配的排序规则有哪些?那就可以从information_schema.collation_character_set_applicab ...
- jQuery之位置
1.offset()获取匹配元素在相对浏览器窗口的偏移量 返回一个对象,包括两个属性.left:相对浏览器窗口左边的距离.top:相对浏览器顶部的距离. $("#div1").o ...
- 【转】ARM交叉编译工具链
原文网址:http://www.veryarm.com/cross-tools 为什么要用交叉编译器? 交叉编译通俗地讲就是在一种平台上编译出能运行在体系结构不同的另一种平台上的程序,比如在PC平台( ...
- bzoj1675 [Usaco2005 Feb]Rigging the Bovine Election 竞选划区
Description It's election time. The farm is partitioned into a 5x5 grid of cow locations, each of wh ...
- C++ Primer 有感(异常处理)
1.异常是通过抛出对象而引发的.该对象的类型决定应该激活哪个处理代码.被选中的处理代码是调用链中与该对象类型匹配且离抛出异常位置最近的那个. 2.执行throw的时候,不会执行跟在throw后面的语句 ...
- 学习《Python核心编程》做一下知识点提要,方便复习(一)
学习<Python核心编程>做一下知识点提要,方便复习. 计算机语言的本质是什么? a-z.A-Z.符号.数字等等组合成符合语法的字符串.供编译器.解释器翻译. 字母组合后产生各种变化拿p ...
- vb.NET基础总结
vb.NET语言的学习,相对于原来的添加了.net平台,也 是基于对vb学习的继承与扩展,是在面向对象基础上的编程语言,vb中学到的控制语句,主要的数据类型,对象的事件,方法,属性等继续应用于vb.n ...