hdu 2102

hdu 2102

#include  < iostream >
using   namespace  std;
const   int  M = 10 ;
char  map[ 2 ][M][M];
bool  vis[ 2 ][M][M];
int  dx[] = {1,0,-1,0} ;
int  dy[] = {0,1,0,-1} ;

struct  point
{
    
int layer;
    
int x,y;
    
int time;
}
Q[ 200 ];

bool  BFS( int  m, int  n, int  t)
{
    point now,next;
    now.layer
=now.x=now.y=now.time=0;
    
int Front=0;
    
int Near=1;
    Q[Front]
=now;
    vis[now.layer][now.x][now.y]
=true;
    
while(Front<Near)
    
{
        now
=Q[Front++];
        
if(map[now.layer][now.x][now.y]=='P')
        
{
            
if(now.time<=t)
                
return true;
            
return false;
        }

        
if(map[now.layer][now.x][now.y]=='#')
            now.layer
=!now.layer;

        
if(map[now.layer][now.x][now.y]=='P')
        
{
            
if(now.time<=t)
                
return true;
            
return false;
        }

        
if(map[now.layer][now.x][now.y]=='*'||map[now.layer][now.x][now.y]=='#')
            
continue;
        
int k;
        
for(k=0;k<4;k++)
        
{
            next.layer
=now.layer;
            next.time
=now.time+1;
            next.x
=now.x+dx[k];
            next.y
=now.y+dy[k];
            
if(!vis[next.layer][next.x][next.y]&&next.x>=0&&next.x<m&&next.y>=0&&next.y<n)
            
{
                Q[Near
++]=next;
                vis[next.layer][next.x][next.y]
=true;
            }

        }

        
    }

    
return false;
}

int  main()
{
    
int T;
    scanf(
"%d",&T);
    
while(T--)
    
{
        
int m,n,t;
        scanf(
"%d%d%d",&m,&n,&t);
        
int i,j,k;
        
for(k=0;k<2;k++)
        
{
            
for(i=0;i<m;i++)
            
{
                
char s[M];
                scanf(
"%s",&s);
                
for(j=0;j<n;j++)
                
{
                    map[k][i][j]
=s[j];
                    vis[k][i][j]
=false;
                }

            }

        }

        
if(BFS(m,n,t))
            printf(
"YES\n");
        
else 
            printf(
"NO\n");
    }

    system(
"pause");
    
return 0;
}

你可能感兴趣的:(hdu 2102)