HDU 5040 BFS + pressure, hdu5040bfs

Source: Internet
Author: User

HDU 5040 BFS + pressure, hdu5040bfs

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 ____/'---'\____. '\\| | //'. /\ |: | // \/_ | -: -|-\ | \-// | \ _ | ''\ ---/'' | \. -\__'-'___/-. /___'.. '/--. --\'.. __. "" '<'. ___ \_< |> _/___. '> '"". | :'-\'.; '\_/';. '/-': | \\'-. \___\/___/. -'// ====== '-. ____'-. ___\_____/___. -'____. -'= --- =' ^ ^ fozu Baoyou 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 





Why is hdu 1181 bfs wa?

/*
A set of data for the landlord
Bb
Tm
0
======================================
There is a small bug, and the AC will be changed.
*/
# Include <iostream>
# Include <string. h>
# Include <queue>
Using namespace std;
# Define N 10020
Struct Point
{
Char pre, end;
};
Point map [N];
Bool vis [N];
Int n;

Void BFS ()
{
Int I;
Char;
Queue <char> Q;
Memset (vis, false, sizeof (vis ));
For (I = 0; I <n; I ++)
If (map [I]. pre = 'B ')
{
Q. push (map [I]. end );
}

While (! Q. empty ())
{
A = Q. front ();
Q. pop ();
For (I = 0; I <n; I ++)
{
If (map [I]. pre = a & map [I]. end = 'M ') //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
{
Printf ("Yes. \ n ");
Return;
}
If (! Vis [I] & map [I]. pre =)
{
Vis [I] = true;
Q. push (map [I]. end );
}
}
}
Printf ("No. \ n ");
}

Int main ()
{
Char str [102];
N = 0;
While (scanf ("% s", str )! = EOF)
{
If (str [0] = '0 ')
{
BFS ();
N = 0;
Continue;
}
Map [n]. pre = str [0];
Map [n]. end = str [(int) strlen (str)-1];
N ++;
}
Return 0;
}... Remaining full text>

Does hdu hdoj 1010 support BFS?

Yes .. Queue struct, a coordinate, a time ..
YES when the time is equal and the coordinates are equal.
When the queue header time is greater than T, NO.
I did not know whether it is feasible ..
0 Ms code ..
# Include <stdio. h>
# Include <string. h>
Const int dir [4] [2] = {}, {0,-1 }};
Const int MAX = 8;
Int n, m;
Char map [MAX] [MAX];
Int dx, dy;
Struct
{
Int x, y;
} Q [2, 1000000];
Int used [MAX] [MAX];
Int vabs (int x)
{
Return x <0? -X: x;
}
Int dis (int x, int y)
{
Return vabs (x) + vabs (y );
}
Int BFS (int x, int y) // first checks whether a path exists.
{
Int tx, ty, I, f =-1, r = 0;
Memset (used, 0, sizeof (used ));
Used [x] [y] = 1;
Q [0]. x = x;
Q [0]. y = y;
While (f! = R ){
F ++;
X = q [f]. x;
Y = q [f]. y;
For (I = 0; I <4; I ++ ){
Tx = x + dir [I] [0];
Ty = y + dir [I] [1];
If (tx = dx & ty = dy) return 1;
If (tx <0 | tx> = n | ty <0 | ty> = m | used [tx] [ty]) continue;
If (map [tx] [ty] = 'X') continue;
Used [tx] [ty] = 1; // mark the point
++ R;
Q [r]. x = tx;
Q [r]. y = ty;
}
}
Return 0;
}
Int able (int x, int y)
{
Memset (used, 0, sizeof (used ));
Int I, f =-1, r = 0, tx, ty, cnt = 0;
Q [0]. x = x;
Q [0]. y = y;
Used [x] [y] = 1;
While (f! = R ){
F ++;
X = q [f]. x;
Y = q [f]. y;
For (I = 0; I <4; I ++ ){
Tx = dir [I] [0] + x;
Ty = dir [I] [1] + y;
If (tx <0 | tx> = n | ty <0 | ty> = m | used [tx] [ty]) continue;
If (map [tx] [ty] = 'X') continue;
Cnt ++;
Used [tx] [ty] = 1;
R ++;
Q [r... the remaining full text>

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.