Drolca

Apologize To Drolca
随笔 - 28, 文章 - 1, 评论 - 6, 引用 - 0
数据加载中……

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

posted on 2010-01-01 22:21 Drolca 阅读(237) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理