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. float的理解

    1.浮动包裹性——浮动具有让元素按displya:inline-block显示(如果没有设置宽度和高度,则它可以显示的尽量窄高 度尽量小).2.浮动破坏性——浮动元素漂浮在标准流之上(但没有脱离文档流 ...

  2. POJ 1190 生日蛋糕(DFS)

    生日蛋糕 Time Limit: 1000MSMemory Limit: 10000KB64bit IO Format: %I64d & %I64u Submit Status Descrip ...

  3. Java 之String.valueOf(obj)

    实例代码如下: String str = null; String uSelectDate = String.valueOf(str); System.out.println("====== ...

  4. WPF笔记(2.4 Grid)——Layout

    原文:WPF笔记(2.4 Grid)--Layout 第一章已经简单介绍过这个容器,这一节详细介绍.Grid一般是用表格(Grid.Row 和Grid.Column )的,比StackPanel更细致 ...

  5. g++ error: expected nested-name-specifier before 'XXX'

    template <typename addrT=int,typename valuT=int,typename stream_addrT=bm_addr,typename stream_siz ...

  6. linux系统下,11款常见远程桌面控制软件

    linux系统下,11款常见远程桌面控制软件 一. Grdc 它是一个用GTK+编写的,适用于gnome桌面环境的远程桌面访问软件.看图: 常见功能: 1.提供全屏,窗口化的远程控制.支持高分辨率下的 ...

  7. codecomb 2086【滑板鞋】

    题目背景 我的滑板鞋时尚时尚最时尚 回家的路上我情不自禁 摩擦 摩擦 在这光滑的地上摩擦 月光下我看到自己的身影有时很远有时很近 感到一种力量驱使我的脚步 有了滑板鞋天黑都不怕 题目描述 你在魅力之都 ...

  8. Java Keyword -- super

    Reference: super When we override superclass's methods, but still want to invoke them, we can use ke ...

  9. 了解XSS攻击

    XSS又称CSS,全称Cross SiteScript,跨站脚本攻击,是Web程序中常见的漏洞,XSS属于被动式且用于客户端的攻击方式,所以容易被忽略其危害性.其原理是攻击者向有 XSS漏洞的网站中输 ...

  10. ios像素点颜色取样

    一.像素点颜色取样 + (UIColor*) getPixelColorAtLocation:(CGPoint)point inImage:(UIImage *)image { UIColor* co ...