## ZOJ Problem Set - 2100 原

木宛城主

ZOJ Problem Set - 2100
Seeding
Time Limit: 1 Second       Memory Limit: 32768 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 <stdio.h>
#include <string.h>
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};//四个方向
char map[10][10];//定义一张地图
int done;
int Flag;
int n,m;
void dfs(int x,int y)
{
int i;
if(x<1 || y<1 || x>n || y>m)   return;//判断是否越界
done++;
if(done==n*m)//如果成功则返回
{
Flag=1;
return;
}
for(i=0;i<4;i++)
{
if(map[x+dir[i][0]][y+dir[i][1]]=='.')
{

map[x+dir[i][0]][y+dir[i][1]]='S';//标记已经耕过的土地
dfs(x+dir[i][0],y+dir[i][1]);
}
}
done--;
map[x][y]='.';
}
int main()
{
int i,j;
memset(map,'S',sizeof(map));
while(scanf("%d%d%*c",&n,&m)!=EOF)
{
if(n==0 && m==0)
break;
done=0;
Flag=0;
for(i=1;i<=n;i++)
{

for(j=1;j<=m;j++)
{
scanf("%c",&map[i][j]);
if(map[i][j]=='S')
done++;
}
getchar();

}

map[1][1]='S';
dfs(1,1);
if(Flag==1)
printf("YES\n");
else
printf("NO\n");
}
return 0;

}

### 木宛城主

ACM Summer Training Warm up

ACM Summer Training Warm up Cover 热身水题 题目 HDU 4500 小Q系列故事——屌丝的逆袭 思路 简单的模拟，一个数组读入数据，一个数组计算维护结果 HDU 2109 Fighting for HDU 思路 简单排序...

SpiffyEight77
2017/08/14
0
0
ZOJ Monthly, January 2018 训练部分解题报告

B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串，每次询问查询两个字符串的一个后缀，该后缀必须是所有字符串中某个字符串的前缀，问该后缀最长时，是多少个字符串的前缀。 思路：对...

Amori
2018/10/25
0
0
ZOJ Problem Set - 1016 Parencodings

Parencodings Time Limit: 2 Seconds Memory Limit: 65536 KB Let S = s1 s2 ... s2n be a well-formed string of parentheses. S can be encoded in two different ways: By an integer seq......

hushhw
2017/11/27
0
0
ZOJ Problem Set - 2104 Let the Balloon Rise（map）

Let the Balloon Rise Time Limit: 2 Seconds Memory Limit: 65536 KB Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' fa......

hushhw
2017/11/27
0
0

2015/10/12
69
0

C#默认OrderBy()函数的排序问题

Airship
29分钟前
2
0
Vue调试神器Vue.js devtools

JamesView
34分钟前
14
0

IGMP互联网组管理协议是TCP/IP 协议族中负责IP组播成员管理的协议，用来在IP主机和与其直接相邻的组播路由器之间建立、维护组播组成员关系。 一、IGMP 简介 IGMP(Internet Group Management...

linuxprobe16
38分钟前
1
0
node-sass 安装失败的各种坑

40分钟前
1
0
Qemu中PCI设备透传（PCI-Assign）源码分析

LastRitter
42分钟前
8
0