标签:des style color os io 数据 for ar
1 5 5 14 S*#*. .#... ..... ****. ...#. ..*.P #.*.. ***.. ...*. *.#..
YES
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<limits.h>
using namespace std;
char mp[2][15][15];
int n,m,t;
int ex,ey,ez;
struct node{
int x,y;
int step;
int f;
};
int dr[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
bool bfs()
{
node st,ed;
st.x=0;
st.y=0;
st.f=0;//记录是第几层
st.step=0;
queue<node>q;
q.push(st);
mp[0][0][0]='*';
while(!q.empty())
{
st=q.front();
q.pop();
if(st.step>t)
break;
if(st.x==ex&&st.y==ey&&st.f==ez)
return true;
for(int i=0;i<4;i++)
{
ed=st;
ed.x+=dr[i][0];
ed.y+=dr[i][1];
ed.step++;
if(ed.x<0||ed.x>=n||ed.y<0||ed.y>=m)
continue;
if(mp[ed.f][ed.x][ed.y]=='#')
{
mp[ed.f][ed.x][ed.y]='*';
ed.f^=1;//上次多校就记得这个东西
if(mp[ed.f][ed.x][ed.y]=='*')
continue;
}
if(mp[ed.f][ed.x][ed.y]=='.'||mp[ed.f][ed.x][ed.y]=='P')
{
mp[ed.f][ed.x][ed.y]='*';
q.push(ed);
}
}
}
return false;
}
int main()
{
int s;
cin>>s;
while(s--)
{
cin>>n>>m>>t;
for(int k=0;k<2;k++)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>mp[k][i][j];
if(mp[k][i][j]=='P')
{
ex=i;
ey=j;
ez=k;
}
}
}
}
if(bfs())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
标签:des style color os io 数据 for ar
原文地址:http://blog.csdn.net/u013582254/article/details/38338905