1 #include<cstdio> 2 #include<queue> 3 #include<cstring> 4 using namespace std; 5 int n,m,mv;char map[103][103];bool vis[103][103]; 6 struct type{ 7 int i,j,mv; 8 bool operator<(const type &oth)const 9 { 10 return mv<oth.mv; 11 } 12 }st; 13 int di[4]={0,-1,0,+1}; 14 int dj[4]={+1,0,-1,0}; 15 bool isout(int i,int j){ 16 if(i<1 || i>n || j<1 || j>m) return true; 17 else return false; 18 } 19 bool is_near_enemy(int i,int j){ 20 for(int k=0;k<4;k++){ 21 type next; 22 next.i=i+di[k],next.j=j+dj[k]; 23 if(!isout(next.i,next.j) && map[next.i][next.j] == 'E') return true; 24 } 25 return false; 26 } 27 void bfs() 28 { 29 priority_queue<type> q; 30 type now,next; 31 memset(vis,0,sizeof(vis)); 32 q.push(st);vis[st.i][st.j]=1; 33 while(!q.empty()) 34 { 35 now=q.top();q.pop(); 36 if(now.mv<=0) continue; 37 for(int k=0;k<4;k++) 38 { 39 next.i=now.i+di[k] , next.j=now.j+dj[k] , next.mv=now.mv; 40 if(vis[next.i][next.j] || isout(next.i,next.j) || map[next.i][next.j]=='E' || map[next.i][next.j] == '#') continue; 41 if(map[next.i][next.j]=='.') next.mv--; 42 else if(map[next.i][next.j]=='T') next.mv-=2; 43 else if(map[next.i][next.j]=='R') next.mv-=3; 44 else if(map[next.i][next.j]=='P') next.mv--; 45 46 if(next.mv<0) continue; 47 if(is_near_enemy(next.i,next.j)) next.mv=0; 48 if(map[next.i][next.j] != 'P') map[next.i][next.j]='*'; 49 vis[next.i][next.j]=1;q.push(next); 50 } 51 } 52 } 53 int main() 54 { 55 int t; 56 scanf("%d",&t); 57 while(t--) 58 { 59 scanf("%d%d%d",&n,&m,&mv); 60 for(int i=1;i<=n;i++){ 61 scanf("%s",map[i]+1); 62 for(int j=1;j<=m;j++) if(map[i][j]=='Y') st.i=i , st.j=j , st.mv=mv; 63 } 64 bfs(); 65 for(int i=1;i<=n;i++){ 66 printf("%s ",map[i]+1); 67 } 68 printf(" "); 69 } 70 }