Save Private Ryan HDU-4845 (shaped pressure BFS | | Layer Shortest)

Source: Internet
Author: User

1, Shape pressure BFS

This kind of pressure is on the key. I have the type of key I have when I press a key to record a point.

BAN[X1][Y1][X2][Y1] Record whether the state between two points is a door or a wall or nothing.

Inc[x][y] Record the key stored at this point (there may be more than one so you need to use binary)

Vis[x][y][key] Mark whether the current point is passed when the owning key type is key

#include <iostream>#include<cstdio>#include<sstream>#include<cstring>#include<map>#include<cctype>#include<Set>#include<vector>#include<stack>#include<queue>#include<algorithm>#include<cmath>#include<bitset>#defineRap (i, A, n) for (int i=a; i<=n; i++)#defineRep (I, A, n) for (int i=a; i<n; i++)#defineLap (I, a, n) for (int i=n; i>=a; i--)#defineLEP (i, A, n) for (int i=n; i>a; i--)#defineRD (a) scanf ("%d", &a)#defineRlld (a) scanf ("%lld", &a)#defineRC (a) scanf ("%c", &a)#defineRS (a) scanf ("%s", a)#definePD (a) printf ("%d\n", a);#definePlld (a) printf ("%lld\n", a);#definePC (a) printf ("%c\n", a);#definePS (a) printf ("%s\n", a);#defineMOD 2018#defineLL Long Long#defineULL unsigned long Long#definePair Pair<int, int>#defineMem (A, B) memset (A, B, sizeof (a))#define_ Ios_base::sync_with_stdio (0), Cin.tie (0)//freopen ("1.txt", "R", stdin);using namespacestd;Const intMAXN = -, INF =0x7fffffff, Ll_inf =0x7fffffffffffffff;intN, M, p, K, S;intBAN[MAXN][MAXN][MAXN][MAXN], INC[MAXN][MAXN];intvis[maxn][maxn][1<<Ten+1];intdis[4][2] = {{1,0}, {-1,0}, {0,1}, {0, -1}};structnode{intx, Y, key, D; Node (intXintYintKeyintd): X (x), Y (y), key (key), d (d) {}};intBFs () {Queue<node>Q; Mem (Vis,0); Q.push (Node (1,1,0| inc[1][1],0)); vis[1][1][0| inc[1][1]] =1;  while(!Q.empty ()) {Node is=Q.front ();        Q.pop ();  for(inti =0; I <4; i++) {Node it (0,0,0,0); It.x= is. x + dis[i][0]; It.y= is. Y + dis[i][1]; if(It.x <1|| It.x > N | | It.y <1|| It.y >m)Continue; if(!ban[it.x][it.y][ is. x][ is. Y]) Continue; if(ban[it.x][it.y][ is. x][ is. y] = =-1|| is. Key & (1<< (ban[it.x][it.y][ is. x][ is. Y]-1)))//If the next point has no wall or door at the current point or has a key to the next point at the current point            {                if(!inc[it.x][it.y]) It.key = is. Key;//if the key is not stored at the next point, pass the current key directly past it.                ElseIt.key = is. Key | INC[IT.X][IT.Y];//If you have a stored key, add the stored key.                if(!Vis[it.x][it.y][it.key]) {Vis[it.x][it.y][it.key]=1; IT.D= is. D +1;                    Q.push (IT); if(It.x = = N && it.y = =m)returnIT.D; }            }        }    }    return-1;}intMain () { while(Cin >> n >> m >> p >>k) {intx1, y1, x2, y2, G, Q; MEM (Ban,-1); Mem (inc,0);  for(inti =1; I <= K; i++) {cin>> x1 >> y1 >> x2 >> y2 >>G; Ban[x1][y1][x2][y2]= Ban[x2][y2][x1][y1] =G; } CIN>>s;  for(inti =1; I <= s; i++) {cin>> x1 >> Y1 >>Q; INC[X1][Y1]|= (1<< (Q-1)); } cout<< BFS () <<Endl; }    return 0;}

Save Private Ryan HDU-4845 (shaped pressure BFS | | Layer Shortest)

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.