标签:des blog http io ar os sp for strong
Description
Input
Output
Sample Input
Sample Output
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
using namespace std;
int t,n,m,T;
char a[2][30][30];
int dic[4][2]={{1,0},{-1,0},{0,1},{0,-1}},mark[2][30][30];
struct node
{
int x,i,j,time;
}p,d;
queue<node> q;
bool check(int x,int y)
{
if(x<0||y<0||x>n||y>m)
return false;
return true;
}
void bfs()
{
p.x=0,p.i=0,p.j=0,p.time=0;
q.push(p);
mark[0][0][0]=1;
while(!q.empty())
{
d=q.front();
q.pop();
for(int i=0;i<4;i++)
{
p.i=d.i+dic[i][0];
p.j=d.j+dic[i][1];
p.x=d.x;
if(a[p.x][p.i][p.j]!=‘*‘&&check(p.i,p.j)&&!mark[p.x][p.i][p.j])
{
if(a[p.x][p.i][p.j]==‘#‘)
{
mark[p.x][p.i][p.j]=1;
if(p.x) p.x=0;
else p.x=1;
}
mark[p.x][p.i][p.j]=1;
p.time=d.time+1;
if(p.time>T)
{
printf("NO\n");
return;
}
if(a[p.x][p.i][p.j]==‘P‘)
{
printf("YES\n");
return ;
}
q.push(p);
}
}
}
printf("NO\n");
}
int main()
{
scanf("%d",&t);
while(t--)
{
memset(mark,0,sizeof(mark));
while(!q.empty()) q.pop();
scanf("%d%d%d",&n,&m,&T);
for(int x=0;x<2;x++)
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>a[x][i][j];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if((a[0][i][j]==‘*‘)&&a[1][i][j]==‘#‘)
a[1][i][j]=‘*‘;
else if((a[0][i][j]==‘#‘)&&a[1][i][j]==‘*‘)
a[0][i][j]=‘*‘;
else if((a[0][i][j]==‘#‘)&&a[1][i][j]==‘#‘)
a[0][i][j]=a[1][i][j]=‘*‘;
}
bfs();
}
return 0;
}
标签:des blog http io ar os sp for strong
原文地址:http://www.cnblogs.com/a972290869/p/4114876.html