Seeding 2100
来源:互联网 发布:互相点击软件 编辑:程序博客网 时间:2024/06/05 02:01
Seeding
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 40 Accepted Submission(s) : 14
Problem Description
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
/*
题意::
给你n*m的矩形土地,‘.’表示可耕种土地 ,‘S’表示石头,问是否可以将土地
全部耕种完。
*/
#include<stdio.h>
#include<string.h>
char a[7][7];
int n,m,cnt,k;
void dfs(int x,int y)
{
if(a[x][y]=='S')
return ;
if(x<1||x>n||y<1||y>m)
return ;
if(k)
return ;
a[x][y]='S';
cnt++;
if(cnt==n*m)
{
k=1;
return ;
}
dfs(x,y+1);
dfs(x,y-1);
dfs(x-1,y);
dfs(x+1,y);
cnt--;
a[x][y]='.';
}
int main(){
int i,j;
while(scanf("%d%d",&n,&m),n|m)
{
cnt=0;
for(i=1;i<=n;i++)
scanf("%s",a[i]+1);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]=='S')
cnt++;
}
}
k=0;
dfs(1,1);
if(k)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
题意::
给你n*m的矩形土地,‘.’表示可耕种土地 ,‘S’表示石头,问是否可以将土地
全部耕种完。
*/
#include<stdio.h>
#include<string.h>
char a[7][7];
int n,m,cnt,k;
void dfs(int x,int y)
{
if(a[x][y]=='S')
return ;
if(x<1||x>n||y<1||y>m)
return ;
if(k)
return ;
a[x][y]='S';
cnt++;
if(cnt==n*m)
{
k=1;
return ;
}
dfs(x,y+1);
dfs(x,y-1);
dfs(x-1,y);
dfs(x+1,y);
cnt--;
a[x][y]='.';
}
int main(){
int i,j;
while(scanf("%d%d",&n,&m),n|m)
{
cnt=0;
for(i=1;i<=n;i++)
scanf("%s",a[i]+1);
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(a[i][j]=='S')
cnt++;
}
}
k=0;
dfs(1,1);
if(k)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
0 0
- Seeding 2100
- ZOJ 2100 Seeding(深搜)
- zoj 2100 Seeding
- zoj 2100 Seeding
- zoj 2100 Seeding(dfs)
- zoj 2100 Seeding
- ZOJ 2100 Seeding
- ZOJ 2100--Seeding【DFS】
- zoj 2100Seeding
- 2100 Seeding【dfs】
- zoj 2100 Seeding 【dfs】
- ZOJ 2100 Seeding(dfs)
- zoj 2100 Seeding
- zoj 2100 Seeding
- ZOJ 2100 Seeding DFS
- zoj 2100 Seeding
- zoj 2100 Seeding
- zoj 2100 Seeding
- 你知道网线接入水晶头的两种正确方法吗? 做个备注,老忘记
- Android中不同包路径下Activity跳转的实现(解决ActivityNotFoundException)
- hdu 4647 Another Graph Game (贪心)
- css去掉iPhone、iPad默认按钮样式
- 修改tcp内核参数:somaxconn
- Seeding 2100
- poj 2774 后缀数组
- 黑马程序员——17,集合,TreeSet,二叉树,泛型
- js图片上传预览
- JAVA学习第十四天
- 【读书笔记】iOS-安全地传输用户密码的方法
- ASP.NET Web API 支持 CORS
- 设计模式特点收藏
- 名人问题