codevs2059 Escape from the Clone Island (portal BFs)

Source: Internet
Author: User

/*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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.