0
点赞
收藏
分享

微信扫一扫

Seeding 2100

624c95384278 2023-04-20 阅读 77


Seeding

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 40   Accepted Submission(s) : 14


Problem Description


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; 
 
 }

举报

相关推荐

0 条评论