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. jQuery 尺寸

    通过 jQuery,很容易处理元素和浏览器窗口的尺寸. jQuery 尺寸 方法 jQuery 提供多个处理尺寸的重要方法: width() height() innerWidth() innerHe ...

  2. Linq XML

    写得比较啰嗦,自己记载备用   1 public class XmlFunction   2     {   3         private static XDocument _doc = new ...

  3. 数据库(学习整理)----1--如何彻底清除系统中Oracle的痕迹(重装Oracle时)

    1.关于重装Oracle数据库: 由于以前装过Oracle数据库,但是版本不怎么样,结果过了试用期之后,我就没有破解和再找合适的版本了!直接使用电脑管家卸载了!可想而知,肯定没清除Oracle痕迹啊! ...

  4. Cocos2dx边学边总结——开篇(一)

    Cocos2dx是一个很好的开源跨平台2d游戏引擎,我们都知道他底层是基于OpenGl ES的,OpenGl 是跨平台的. 正是得益于这点 Cocos2dx的显示部分可以很好的跨平台运作,笔者认为 未 ...

  5. Win32中GDI+应用(四)--- 位图的打开与显示

    显示位图,你应该使用GDI+里面的Bitmap类或者Image类,这两个类都提供了方法从硬盘上的一个文件打开文件,创建相应的内存中的位图对象的工作.然后你可以使用Graphics类的DrawImage ...

  6. 设计模式之 State 状态模式

    状态模式的核心在于 1. 状态的转换导致行为(Handle)的差异,比如人的状态是饿的时候,吃(Handle)的行为是2个馒头,人状态是不太饿的时候,吃(Handle)的行为是半个馒头 2. Stat ...

  7. smali 语法之try catch语句

    # virtual methods .method public onClick(Landroid/view/View;)V .locals 4 .parameter "v" .p ...

  8. 从文章"避免复制与粘贴"到文章"Extract Method"的反思(2)

    好了.在上一篇里面讲了讲怎么把临时变量应该从函数里面剔除去.这个过程叫做从临时变量变成查询 那么接下来我们聊聊把代码提炼成函数,有叫做用函数对象取代函数 那么,问题来了:在函数中什么样的代码是需要被提 ...

  9. 在HTML页面布局中,position的值有几种,默然的值是什么

    <!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8&qu ...

  10. 非常好用的正则表达式"\\s+" - 匹配任意空白字符

    说起来,博主使用过的正则场景虽然不多,但是就是在这当中,我发现"\\s+"真好用! 详解 "\\s+" 正则表达式中\s匹配任何空白字符,包括空格.制表符.换页 ...