题意:题干讲得很明确了。
思路:简单的BFS。我做的时候在两个地方被坑了。一,走到传送门也需要花费时间。二,花费的时间小于等于限制时间即可,而不需要小于他。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int n,m,r;
char mmap[2][12][12];
bool vis[2][12][12];
int cx[] ={0,0,-1,1};
int cy[] ={1,-1,0,0};
struct ha
{int x,y,z;int step;bool operator <(const struct ha &a) const{return step>a.step;}
}tep,now;
int main()
{int T; scanf("%d",&T);while(T--){memset(vis,0,sizeof(vis));scanf("%d%d%d",&n,&m,&r);for(int i=0;i<2;i++)for(int j=0;j<n;j++)scanf("%s",mmap[i][j]);now.x=now.y=now.z=now.step=0;/*for(int i=0;i<2;i++)for(int j=0;j<n;j++)for(int k=0;k<m;k++)if(mmap[i][j][k]=='S') now.x=i,now.y=j,now.z=k;*/if(now.x==-1){printf("NO\n");continue;}priority_queue<struct ha> qu;qu.push(now);bool flag=0;while(!qu.empty()){tep =qu.top(); qu.pop();if(vis[tep.z][tep.x][tep.y]) continue;if(mmap[tep.z][tep.x][tep.y]=='*') continue;if(mmap[tep.z][tep.x][tep.y]=='#'){tep.z=!tep.z;vis[tep.z][tep.x][tep.y]=1;qu.push(tep);continue;}vis[tep.z][tep.x][tep.y]=1;if(mmap[tep.z][tep.x][tep.y]=='P'&&tep.step<=r){//if(tep.step>=r) break;//printf("%d\n",tep.step);printf("YES\n");flag=1;break;}for(int i=0;i<4;i++){now=tep;int tx=tep.x+cx[i],ty=tep.y+cy[i];if(tx<0||tx>=n||ty<0||ty>=m) continue;now.x=tx; now.y=ty; now.step=tep.step+1;if(mmap[tep.z][tx][ty]=='*') continue;else if(mmap[tep.z][tx][ty]=='#') now.z=!now.z;//elsequ.push(now);}}if(!flag) printf("NO\n");}return 0;
}