HDU 2102 A计划

来源:互联网 发布:java script没有提示 编辑:程序博客网 时间:2024/05/18 14:26

水bfs。 只需要判断一下 #之后还是*或#都是死路。

只有两层。

#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>#include<iostream>#include<list>#include<set>#include<vector>#include<cmath>#define INF 0x7fffffff#define eps 1e-8#define LL long long#define PI 3.141592654#define CLR(a,b) memset(a,b,sizeof(a))#define FOR(i,a,n) for(int i= a;i< n ;i++)#define FOR0(i,a,b) for(int i=a;i>=b;i--)#define pb push_back#define mp make_pair#define ft first#define sd second#define acfun std::ios::sync_with_stdio(false)#define SIZE 10+1using namespace std;struct lx{    int x,y,z,t;    void init(int xx,int yy,int zz,int tt)    {        x=xx,y=yy,z=zz,t=tt;    }}thend,start;char g[2][SIZE][SIZE];int n,m;int xx[]={0,0,-1,1};int yy[]={-1,1,0,0};void bfs(){    bool vis[2][SIZE][SIZE];    CLR(vis,0);    queue<lx>q;    q.push(start);    vis[0][0][0]=1;    while(!q.empty())    {        lx tmp=q.front();        q.pop();        //printf("%d %d %d t=%d\n",tmp.x,tmp.y,tmp.z,tmp.t);        //system("pause");        if(tmp.t>thend.t)continue;        if(tmp.x==thend.x&&tmp.y==thend.y&&tmp.z==thend.z&&tmp.t<=thend.t)        {            puts("YES");            return;        }        FOR(k,0,4)        {            int x=tmp.x+xx[k];            int y=tmp.y+yy[k];            int z=tmp.z;            lx now;            if(x<0||y<0||x>=n||y>=m||g[z][x][y]=='*'||vis[z][x][y])continue;            vis[z][x][y]=1;            if(g[z][x][y]=='#')            {                z^=1;                if(g[z][x][y]=='*'||g[z][x][y]=='#')continue;            }            now.init(x,y,z,tmp.t+1);            q.push(now);        }    }    puts("NO");}int main(){    int t;    scanf("%d",&t);    while(t--)    {        int tt;        scanf("%d%d%d",&n,&m,&tt);        FOR(k,0,2)        FOR(i,0,n)        {            char str[SIZE];            scanf("%s",str);            FOR(j,0,m)            {                g[k][i][j]=str[j];                if(str[j]=='P')                    thend.init(i,j,k,tt);            }        }        start.init(0,0,0,0);        bfs();    }}


0 0