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

题意:一个播种的机器,不可以走走过的区域,也不可以走有石头(S)的区域,问是否能走遍图中所有的不含石头的区域

题解:将走过的区域标记为有石头的区域,一直走如果可以走完即ans==s(走过的区域等于所有不含石头的区域)则返回输出YES否则回溯

并清除标记,换其他路线继续搜索,直至结束

#include<stdio.h>
#include<string.h>
char map[10][10];
int n,m,ans,ok,s;
void dfs(int x,int y)
{
int i,j;
int move[4][2]={0,1,0,-1,1,0,-1,0};
if(ans==s)
ok=1;
for(i=0;i<4;i++)
{
int tx=x+move[i][0];
int ty=y+move[i][1];
if(0<tx&&tx<=n&&0<ty&&ty<=m&&map[tx][ty]=='.')
{
map[tx][ty]='S';
ans++;
dfs(tx,ty);
map[tx][ty]='.';
ans--;
}
}
}
int main()
{
int j,i;
while(scanf("%d%d",&n,&m),n|m)
{
ans=0;
ok=0;
s=0;
for(i=1;i<=n;i++)
{
getchar();
for(j=1;j<=m;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='.')
s++;
}
}
ans++;
map[1][1]='S';
dfs(1,1);
if(!ok)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}

  

zoj 2100 Seeding的更多相关文章

  1. Num 36 : ZOJ 2100 [ 深度优先搜索算法 ] [ 回溯 ]

    该题是用回溯法来解决的题: 题目: Seeding Time Limit: 2 Seconds      Memory Limit: 65536 KB It is spring time and fa ...

  2. HZNU Training 1 for Zhejiang Provincial Collegiate Programming Contest

    赛后总结: TJ:今天我先到实验室,开始看题,一眼就看了一道防AK的题目,还居然觉得自己能做wwww.然后金姐和彭彭来了以后,我和他们讲了点题目.然后金姐开始搞dfs,我和彭彭看榜研究F题.想了很久脑 ...

  3. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  4. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

  5. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  6. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  7. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  8. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  9. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

随机推荐

  1. winform程序中界面的跳转问题

    首先是我们进行窗口间的跳转,尤其注意的是winform程序里面的空间都是中线程安全的.但是注意的是如果你在一个线程中操纵另外的控件,这时候会提示你一个错误,这个错误的解决方法准备单独的在另一篇文章中来 ...

  2. JavaScript DOM编程艺术第二版学习(1/4)

    接下来项目需要网页相关知识,故在大牛的指引下前来阅读本书. 记录方式:本书分四部分阅读,完成阅读之后会多写一篇包括思维导图的算是阅读指南的东西,浏览的童鞋看着指南可以跳过一些不必要的坑~ 当前水平:H ...

  3. SVM推导

    标准最大margin问题 假设data是linear seperable的 优化目标 希望 margin(w),i.e, 最小的点到直线的距离 最大 即是要得到最右的线,它对噪声的鲁棒性最好 得到的分 ...

  4. c语言字符数组与字符串的使用详解

    转自:http://www.jb51.net/article/37456.htm 1.字符数组的定义与初始化字符数组的初始化,最容易理解的方式就是逐个字符赋给数组中各元素.char str[10]={ ...

  5. 读书笔记之 - javascript 设计模式 - 命令模式

    本章研究的是一种封装方法调用的方式.命令模式与普通函数有所不同.它可以用来对方法调用进行参数化处理和传送,经过这样处理过的方法调用可以在任何需要的时候执行. 它也可以用来消除调用操作的对象和实现操作的 ...

  6. 开发错误日志之No matching bean of type [xxx] found for dependency

    No matching bean of type [org.springframework.data.mongodb.core.MongoTemplate] found for dependency ...

  7. Ajax跨域访问问题-方法大全

    Case I. Web代理的方式 (on Server A) 即用户访问A网站时所产生的对B网站的跨域访问请求均提交到A网站的指定页面,由该页面代替用户页面完成交互,从而返回合适的结果.此方案可以解决 ...

  8. 帝国cms 灵动标签【列表页】调用当前父栏目下的所有子栏目

    <? $bclassid = $class_r[$GLOBALS[navclassid]][bclassid]; //获取当前父栏目ID ?> [e:loop={"select ...

  9. Python 手册——解释器及其环境

    错误处理: 有错误发生时,解释器打印一个错误信息和栈跟踪(监视)器?.交互模式下,它返回主提示符,如果从文件 输入执行,它在打印栈跟踪器后以非零状态退出.(异常可以由try语句中的except子句来控 ...

  10. python中的buildin函数详解(第一篇)

    这会是很长的一个帖子,因为我打算从python最基础的东西开始,尝试去完全的掌握它,buildin中有一些常用的函数比如 abs, open, setattr, getattr, 大家都很了解他们的用 ...