2014 ACM/ICPC Asia Regional Beijing online
For N * n Matrices
M start point, t end point
Cameras with starting directions north N, East e, South S, and West W can be detected in the range of self-directed 1 grid and Rotate 90 ° clockwise every 1 second.
If there is a lamp in front or a place on your own, it takes 3 seconds to move it, or wait for a second to move it.
BFS priority queue
Enable the three-dimensional hash array to determine the weight. The third dimension is the waiting time at this point. Open it to 4 (the camera turns around)
When will the camera view the processing of each vertex in the figure, and store it in the map array with a binary compression?
Then the regular BFS Solution
In the competition, no case was left blank .... I found a half-day error .....
/* _ Ooooo _ o8888888o 88 ". "88 (|-_-|) O \=/o ____/'---'\____. '\\| | //'. /\| |: | // _ | -: -| \-// | \ _ | ''\ ---/'' | \. -\__'-'___/-. /___'.. '/--. --\'.. __. "" '<'. ___ \_< |> _/___. '> '"". | :'-\'.; '\_/';. '/-': | \\'-. \___\/___/. -'// ====== '-. ____'-. ___\_____/___. -'____. -'= --- =' ^ ^ fozubaoy Ou pass system test! */# Include "stdio. H "# include" string. H "# include" queue "using namespace STD; int INF = 0x3f; int dir [4] [2] = }, {0,-1 }}; struct node {int X, Y, step, wait; // step records the number of steps and wait records the waiting time of friend bool operator <(node N1, node N2) {return n1.step> n2.step; }}; int s_x, s_y, N; int B [5]; char STR [510] [510]; int map [510] [510], hash [510] [510] [5]; // when will each point of MAP storage be seen, hash weight the third dimension is the waiting time at this point int BFS () {priority_queue <No De> q; node cur, next; int I, time; cur. X = s_x; cur. y = s_y; cur. step = 0; cur. wait = 0; q. push (cur); memset (hash, INF, sizeof (hash); hash [cur. x] [cur. y] [0] = 0; while (! Q. empty () {cur = Q. top (); q. pop (); If (STR [cur. x] [cur. y] = 'T') return cur. step; for (I = 0; I <4; I ++) {next. X = cur. X + dir [I] [0]; next. y = cur. Y + dir [I] [1]; If (next. x <0 | next. x> = n | next. Y <0 | next. y> = n) Continue; If (STR [next. x] [next. y] = '#') continue; time = B [cur. step % 4]; If (Map [cur. x] [cur. y] & time) = Time | (Map [next. x] [next. y] & time) = Time) // next is displayed at the current or next vertex. step = cur. step + 3; else next. step = cur. step + 1; next. wait = 0; If (next. step
HDU 5040 BFS + pressure