Test instructions: Give a map, ' X ' to take a step at the cost of 2, '. ' Take one step at the cost of 1, and ask for the smallest price from S to T. Bare priority queue.
1 #pragmaComment (linker, "/stack:10240000,10240000")2 3#include <iostream>4#include <cstdio>5#include <algorithm>6#include <cstdlib>7#include <cstring>8#include <map>9#include <queue>Ten#include <deque> One#include <cmath> A#include <vector> -#include <ctime> -#include <cctype> the#include <Set> - - using namespacestd; - + #defineMem0 (a) memset (a, 0, sizeof (a)) - #defineLson L, M, RT << 1 + #defineRson m + 1, R, RT << 1 | 1 A #definedefine_m int m = (L + r) >> 1 at #defineRep (A, b) for (int a = 0; a < b; a++) - #defineLowbit (x) ((x) & (-(x))) - #defineCONSTRUCTINT4 (name, a, B, C, D) name (int a = 0, int b = 0, int c = 0, int d = 0): A (a), B (b), C (c), D (d) {} - #defineCONSTRUCTINT3 (name, a, B, c) name (int a = 0, int b = 0, int c = 0): A (a), B (b), C (c) {} - #defineConstructInt2 (name, a, b) name (int a = 0, int b = 0): A (a), B (b) {} - intypedefDoubledb; -typedefLong LongLL; totypedef pair<int,int>PII; +typedef multiset<int>MSI; -typedef multiset<int>:: iterator msii; thetypedefSet<int>si; *typedefSet<int>:: iterator sii; $typedef vector<int>VI;Panax Notoginseng - Const intdx[8] = {1,0, -1,0,1,1, -1, -1}; the Const intdy[8] = {0, -1,0,1, -1,1,1, -1}; + Const intMAXN = 1e5 +7; A Const intMAXM = 1e5 +7; the Const intMAXV = 1e7 +7; + Const intMD = 1e9 +7; - Const intINF = 1e9 +7; $ Const DoublePI = ACOs (-1.0); $ Const DoubleEPS = 1e-Ten; - - structNode { the intx, y, cost; - BOOL operator< (ConstNode &a)Const {Wuyi returnCost >A.cost; the } - ConstructInt3 (Node, x, y, cost); Wu }; - AboutPriority_queue<node>Q; $ - intN, M; - Chars[ -][ -]; - A voidBFS (intX1,intY1,intX2,inty2) { + while(!Q.empty ()) Q.pop (); theQ.push (Node (x1, y1,0)); -S[X1][Y1] ='*'; $ while(!Q.empty ()) { theNode top =Q.top (); Q.pop (); the if(top.x = = x2 && top.y = =y2) { thecout << top.cost <<Endl; the return ; - } in for(inti =0; I <4; i++) { the intx = top.x + dx[i], y = top.y +Dy[i]; the if(x >=0&& x < n && y >=0&& y < M && (s[x][y] = ='.'|| S[x][y] = ='x')) { AboutQ.push (Node (x, Y, Top.cost + (s[x][y] = ='.'?1:2))); theS[x][y] ='*'; the } the } + } -Puts"Poor ANGEL have to stay in the prison all he life."); the }Bayi the intMain () { the //freopen ("In.txt", "R", stdin); - while(Cin >> N >>m) { - intx1, x2, y1, y2; the for(inti =0; I < n; i++) { thescanf"%s", S +i); the for(intj =0; J < M; J + +) { the if(S[i][j] = ='R') { -X1 =i; theY1 =J; theS[I][J] ='.'; the }94 if(S[i][j] = ='a') { thex2 =i; they2 =J; theS[I][J] ='.';98 } About } - }101 BFS (x1, y1, x2, y2);102 }103 return 0;104}View Code
[hdu1242] Priority queue