#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
#define rd(x) scanf("%d",&x)
#define rdd(x,y) scanf("%d%d",&x,&y)
#define rddd(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rdddd(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define rds(s) scanf("%s",s)
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
const int N = 1005;
const int M=5e5+10;
const int inf=1e9;
const double eps=1e-5;
const int MOD=1e9+7;
int n,m,mv;
char s[N][N];
struct node{
int x,y;
node(){}
node(int _r,int _c){
x=_r,y=_c;
}
};
int maxLeft[N][N];
bool vis[N][N];
queue<node>q;
int dir[]={0,1,0,-1,1,0,-1,0};
int main()
{
#ifndef ONLINE_JUDGE
freopen("aaa","r",stdin);
freopen("output1","w",stdout);
#endif
int T;
rd(T);
while(T--){
rddd(n,m,mv);
for(int i=1;i<=n;i++)
scanf("%s",s[i]+1);
int staCol,staRow;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++) if(s[i][j]=='Y'){
staRow=i;staCol=j;
break;
}
while(!q.empty()) q.pop();
node start=node(staRow,staCol);
q.push(start);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) maxLeft[i][j]=-1,vis[i][j]=0;
maxLeft[staRow][staCol]=mv;
vis[staRow][staCol]=1;
while(!q.empty()){
node u=q.front();q.pop();
vis[u.x][u.y]=0;
for(int k=0;k<8;){
int dx=dir[k++]+u.x;
int dy=dir[k++]+u.y;
if(dx<1 || dx >n || dy<1 || dy > m || s[dx][dy]=='E' || s[dx][dy]=='Y' || s[dx][dy]=='#') continue;
int w=maxLeft[u.x][u.y];
if(s[dx][dy]=='.' || s[dx][dy]=='P') w-=1;
else if(s[dx][dy]=='T') w-=2;
else if(s[dx][dy]=='R') w-=3;
if(w<0 ) continue;
for(int z=0;z<4;z++)
if(dx+dir[z*2]>0 && dx+dir[z*2]<=n && dy+dir[z*2+1]>0 && dy+dir[z*2+1]<=m && s[dx+dir[z*2]][dy+dir[z*2+1]]=='E') w=0;
if(w>maxLeft[dx][dy]){
maxLeft[dx][dy]=w;
if(w){
q.push(node(dx,dy));
vis[dx][dy]=1;
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
if(maxLeft[i][j]>-1 && s[i][j]!='P' && s[i][j]!='Y') printf("*");
else printf("%c",s[i][j]);
puts("");
}
puts("");
}
return 0;
}
hdu3345 bfs,陷阱较多
最新推荐文章于 2018-05-13 10:50:57 发布