码迷,mamicode.com
首页 > 其他好文 > 详细

Zoj 2100 Seeding

时间:2017-05-28 13:57:20      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:dfs   lag   post   pos   ++   for   can   include   printf   

 
<pre class="html" name="code">#include<stdio.h>   
char map[8][8];  
int visited,flag;  
int n,i,j,m;  
void dfs(int x,int y)  
{  
    if( x<0 || y<0 || x>=n || y>=m) 
        return;  
   if(map[x][y]!=‘.‘)  
        return;  
   if(flag)  
       return;  
   map[x][y] = ‘s‘;  
    visited++;  
   if(visited == n*m) 
   {  
       flag=1;  
       return;  
   }  
    dfs(x+1,y); 
    dfs(x-1,y);  
    dfs(x,y+1);  
    dfs(x,y-1);  
    visited--; 
    map[x][y]=‘.‘; 
}  
  
int main(void)  
{  
    while(scanf("%d%d",&n,&m) && n && m)  
    {  
        for(i=0;i<n;i++)  
            scanf("%s",map[i]);  
          
        for(i = 0 , visited = 0 ; i < n ; i++)  
            for(j = 0;j<m;j++)  
                if(map[i][j]==‘S‘)   
                    visited++;  
          
        flag = 0;  
        dfs(0,0);  
        if(flag) printf("YES\n");  
        else printf("NO\n"); 
          
    }    
    return 0;  
}  


   

Zoj 2100 Seeding

标签:dfs   lag   post   pos   ++   for   can   include   printf   

原文地址:http://www.cnblogs.com/liguangsunls/p/6915573.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!