/*and the common maze problem is just a lot of stuff called a portal. The handling of the Portal: whenever you run to a portal, the points around all the rest of the portals are queued and the portals don't take time to travel between them and go from the point that is not the portal to the portal, and it does not take much time (as if to say nonsense). So Judge*/#include<iostream>#include<cstdio>#include<cstdlib>#include<queue>#include<algorithm>#defineMAXN 5010using namespacestd;intN,m,v,f[maxn][maxn],num;CharS[MAXN][MAXN];intxx[5]={0,0,0,1,-1};intyy[5]={0,1,-1,0,0};intSx,sy,ex,ey;structnode{intXi,yi; intV;};structnode{intXi,yi;} door[510];queue<node>Q;intMain () {scanf ("%d%d%d",&n,&m,&v); for(intI=1; i<=n;i++) for(intj=1; j<=m;j++) {cin>>S[i][j]; if(s[i][j]=='Y') {SX=i;sy=J; S[I][J]='*'; } if(s[i][j]=='C') {ex=i;ey=J; S[I][J]='*'; } if(s[i][j]=='P') {num++; Door[num].xi=i; Door[num].yi=J; }} node tmp; Tmp.xi=SX; Tmp.yi=Sy; Tmp. V=0; Q.push (TMP); F[sx][sy]=1; while(!Q.empty ()) {Node now=Q.front (); Q.pop (); intnx=Now.xi; intny=Now.yi; if(s[nx][ny]=='*')//normal point as long as the surrounding points are queued for(intI=1; i<=4; i++) { intox=nx+Xx[i]; intoy=ny+Yy[i]; if(ox>0&&ox<=n&&oy>0&&oy<=m&&f[ox][oy]==0&&s[ox][oy]!='#') {F[ox][oy]=1; Node TMEP; Tmep.xi=Ox; Tmep.yi=Oy; if(s[ox][oy]=='*') TMEP. V=now. v+v; ElseTMEP. V=now. V//judge whether to +timeQ.push (TMEP); if(ox==ex&&oy==ey) {printf ("%d", now. V); return 0; } } } if(s[nx][ny]=='P')//Portal handled separately for(intI=1; i<=num;i++)//all portals, of course, include himself. { intnx=Door[i].xi; intny=Door[i].yi; for(intj=1; j<=4; j + +) { intox=nx+Xx[j]; intoy=ny+Yy[j]; if(ox>0&&ox<=n&&oy>0&&oy<=m&&f[ox][oy]==0&&s[ox][oy]!='#') {F[ox][oy]=1; Node TMEP; Tmep.xi=Ox; Tmep.yi=Oy; if(s[ox][oy]=='*') TMEP. V=now. v+v; ElseTMEP. v=Now . V Q.push (TMEP); if(ox==ex&&oy==ey) {printf ("%d", now. V); return 0; } }}}} printf ("Screw you!"); return 0;}
codevs2059 Escape from the Clone Island (portal BFs)