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的更多相关文章

  1. zoj 2100 Seeding

    Seeding Time Limit: 2 Seconds      Memory Limit: 65536 KB It is spring time and farmers have to plan ...

  2. Seeding(dfs)

    Seeding Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submi ...

  3. Oracle Warehouse Builder(OWB) 安装报seeding owbsys错误的解决

    今天在RHEL6.4上安装Oracle Warehouse Builder 11.2时在最后一步报错,打开日志查看有例如以下信息: main.TaskScheduler timer[5]2014052 ...

  4. JAVA UUID 生成

    UUID是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的.通常平台会提供生成UUID的API.UUID按照开放软件基金会(OSF)制定的标准计算,用到了以太网卡地址.纳秒级时间.芯 ...

  5. 超像素经典算法SLIC的代码的深度优化和分析。

    现在这个社会发展的太快,到处都充斥着各种各样的资源,各种开源的平台,如github,codeproject,pudn等等,加上一些大型的官方的开源软件,基本上能找到各个类型的代码.很多初创业的老板可能 ...

  6. 使用wget命令时发生错误

    用的是centos6.5, 当我使用命今 sudo wget https://cmake.org/files/v3.6/cmake-3.6.1.tar.gz 下载个cmake的包时, 发生了这样的错误 ...

  7. theano学习

    import numpy import theano.tensor as T from theano import function x = T.dscalar('x') y = T.dscalar( ...

  8. Azure SQL Database Active Geo-Replication简介

    笔者在<迁移SQL Server 数据库到 Azure SQL 实战>一文中,介绍了如何把一个本地版的 SQL Server 数据库迁移到 Azure SQL Database.迁移虽然顺 ...

  9. Code First :使用Entity. Framework编程(6) ----转发 收藏

    Chapter6 Controlling Database Location,Creation Process, and Seed Data 第6章 控制数据库位置,创建过程和种子数据 In prev ...

  10. ASP.NET Identity系列教程(目录)

    $(document).ready(function(){ $("#hide").click(function(){ $(".en").hide(); }); ...

随机推荐

  1. Jmeter -- 初体验

    一.Jmeter参数 在命令行输入Jmeter --help得到以下信息: To run Apache JMeter in GUI mode:Double-click on the ApacheJMe ...

  2. TabHost刷新activity的方法

    在android中,使用tabHost的时候,如果tab被点击,该tab所对应的activity被加载了,从别的tab切换回来的时候,activity不会再次被创建了(onCreate),所以要想每次 ...

  3. C# System.Uri类_获取Url的各种属性_文件名_参数_域名_端口等等

    System.Uri类用于处理Uri地址信息,常用到它的地方有,相对Uri地址转绝对Uri地址,获取Uri的某部分信息等等,可以说是一个非常有用的类. 一.属性 AbsolutePath 获取 URI ...

  4. Python IDE的选择和安装

    安装好Python后我们需要选择合适自己的IDE进行学习,虽然利用python默认的编辑器,或者直接文档编辑也可以进行基础的学习,但总归不是太方便,能够开发python项目的IDE很多,如sublim ...

  5. MySQL无法重启问题解决Warning: World-writable config file ‘/etc/my.cnf’ is ignored

    MySQL无法重启问题解决Warning: World-writable config file ‘/etc/my.cnf’ is ignored

  6. 重大新闻:借贷宝不用绑卡了,借贷宝APP推出肖像识别新功能!

    动动手指,20元人民币立即到手:http://www.cnblogs.com/mfryf/p/4754384.html 滴滴打车烧钱十几个亿,狂送打车券,很多人天天免费坐车! 去年年初百度钱包注册奖励 ...

  7. SHDP--Working with HBase(三)之HBase+Phoenix实现分页

    先简单讲讲只用HBase来实现分页的思路: HBase利用scan来扫描表,通过startKey,stopKey来确定扫描范围,在需要进行分页时可以结合HBase提供的PagefFilter过滤扫描的 ...

  8. 3 x 8 = 23(火了)

    颜回爱学习,德性又好,是孔子的得意门生.一天,颜回去街上办事,见一家布店前围满了人.他上前一问,才知道是买布的跟卖布的发生了纠纷. 只听买布的大嚷大叫:「三八就是二十三,你为啥要我二十四个钱?」颜回走 ...

  9. Ajax——ajax调用数据总结

    在做人事系统加入批量改动的功能中,须要将前台中的数据传给后台.后台并运行一系列的操作. 通过查询和学习了解到能够通过ajax将值传入到后台,并在后台对数据进行操作. 说的简单点.就是ajax调用后台的 ...

  10. 通过ant脚本编译打包android工程

    通过ant脚本,编译打包android工程 1.Android程序编译.打包.签名.发布的三种方式:  方式一:命令行手动编译打包  方式二:使用ant自动编译打包  方式三:使用eclipse+AD ...