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. html-----003

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Bootstrap 3 支持 IE8

    Bootstrap 3 支持 IE8 <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries ...

  3. CoffeeScript飞一样的写javascript

    之前看到同事在使用coffeescript写js,当我看到那简介的coffee文件,就深深的被coffescript吸引了,简洁的语法,熟练之后会大大提升javascript的开发速度,写脚本也能像飞 ...

  4. laravel学习:修改时区

    config/app.php 'timezone' => 'UTC', 改为 'timezone' => 'PRC',

  5. [转]基于Spring + Spring MVC + Mybatis 高性能web构建

    http://blog.csdn.net/zoutongyuan/article/details/41379851/ 一直想写这篇文章,前段时间 痴迷于JavaScript.NodeJs.Angula ...

  6. MATLAB灰度图、中值滤波图

    x=imread(‘x.jpg’); x=rbg2gray(x);  %转成灰度图像 k=medfilt2(x);   %中值滤波,默认为3X3矩阵 figure, imshow(k); medfil ...

  7. C语言怎么计算程序所花时间

    在函数之前和之后取得系统的时间,然后相减就是函数执行时间,不过在取得系统时间的时候,最小单位是微秒 具体代码如下: #include<stdio.h> #include<iostre ...

  8. 常用machine learning数据集

    ImageNet:非商业化的可视化大数据 截止到2015年5月1日,ImageNet数据库拥有超过1500万的图像. cifar10:10类物体识别数据集 数据集中包含60,000幅32*32图像,共 ...

  9. c# 函数注释 显示换行 ,

    格式:<para>………..</para> /// <summary> /// <para>把html中的随机汉字转换为图片 调用如下:</par ...

  10. QT5.1.1中MinGW4.8的环境变量配置

    1.右击“我的电脑”图标,在弹出的菜单上选择“属性(R)”菜单项. 2.选择“高级”选项卡.点击“环境变量”按钮. 3.点击“新建(W)”按钮,新建环境变量:MINGW_HOME,变量值为MinGW的 ...