标签:space problem scribe eve output des memset dimens nbsp
5 3 3 100 ... .E. ..Y 5 6 4 ...... ....PR ..E.PY ...ETT ....TT 2 2 100 .E EY 5 5 2 ..... ..P.. .PYP. ..P.. ..... 3 3 1 .E. EYE ...Sample Output
... .E* .*Y ...*** ..**P* ..E*PY ...E** ....T* .E EY ..*.. .*P*. *PYP* .*P*. ..*.. .E. EYE .*.
代码:
#include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std; int dir[4][2]={0,1,1,0,0,-1,-1,0}; int t,n,m,val,head,tail,tx,ty,d; char map[101][101]; int vis[101][101]; struct que { int x,y,mv; friend bool operator <(que a,que b) { return a.mv<b.mv; } }cur; int judge(int x,int y) { if(x<0||y<0||x>=n||y>=m)return 0; return 1; } int check(int x,int y) { for(int i=0;i<4;i++) if(judge(x+dir[i][0],y+dir[i][1])&&map[x+dir[i][0]][y+dir[i][1]]==‘E‘)return 1; return 0; } int check1(int x,int y) { if(vis[x][y]<0)return 0; if(map[x][y]==‘P‘||map[x][y]==‘Y‘)return 0; return 1; } int main() { priority_queue <que>q; scanf("%d",&t); while(t--) { scanf("%d%d%d",&n,&m,&val); head=tail=0; memset(vis,-1,sizeof(vis)); for(int i=0;i<n;i++) scanf("%s",map[i]); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(map[i][j]==‘Y‘){ cur.x=i,cur.y=j; cur.mv=val; q.push(cur); vis[i][j]=val; break;} } } while(!q.empty()) { for(int i=0;i<4;i++) { tx=q.top().x+dir[i][0]; ty=q.top().y+dir[i][1]; if(!judge(tx,ty)||map[tx][ty]==‘#‘||map[tx][ty]==‘E‘)continue; if(map[tx][ty]==‘T‘)d=q.top().mv-2; else if(map[tx][ty]==‘R‘)d=q.top().mv-3; else d=q.top().mv-1; if(check(tx,ty)&&d>0)d=0; if(d>vis[tx][ty]) { vis[tx][ty]=d; if(d>0) {cur.x=tx; cur.y=ty; cur.mv=d; q.push(cur);} } } q.pop(); } for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { if(check1(i,j))putchar(‘*‘); else putchar(map[i][j]); } cout<<endl; } cout<<endl; } }
标签:space problem scribe eve output des memset dimens nbsp
原文地址:http://www.cnblogs.com/8023spz/p/7217039.html