, seconds to reach the Target position, let me show you the Way.1s: (0,0), (1,0) 2s: (1,0), (+) 3s: (+)--(2,1) 4s: (2,1), (2,2) 5s: ( 2,2) (2,3) 6s: (2,3), (1,3) 7s: (1,3), (1,4) 8s:fight at (1,4) 9s:fight at (1,4) 10s: (1,4), (1,5) 11s: (1,5)- > (2,5) 12s: (2,5)--(3,5) 13s: (3,5)--(4,5) 14s:fight at (4,5) Finishgod, our poor hero. FINISHAuthorIgnatius.lIdeas:See the picture to know is search .....Initially want to use DFS because DFS is good to write, but because the shortest path required, DFS
Topic Portal1 /*2 Test instructions: from one count to another, change one number at a time, and each is a prime number3 BFS: First pre-treatment of 1000 to 9999 prime, simple BFS a bit. I didn't output impossible AC, the data was a little weak.4 */5 /************************************************6 Author:running_time7 Created time:2015-8-2 15:46:578 File Name:P oj_3126.cpp9 ******************************
Open a three-dimensional marker array to mark whether Ignatius has reached the position with the key.Since the number of keys is up to 10, you can use state compression to doUse 1 and 0 to indicate that there is no key I, so that this person can get the key state to be used in binary number representationFind the minimum value with BFS#include #include #include #include using namespace Std;const int MAXN = 30;const int inf = 0X7FFFFFFF;int vis[maxn][m
Previously with DFS pruning AC, http://www.cnblogs.com/ediszhao/p/4741825.html, this time with Bfs+priority_queue to try to solve the problemTest instructions: Rescue operations, Angel R has a number of friends a (friends, here is a few times, not see test instructions), Angels are locked in a cell, waiting for friends to save, to save the shortest distance angel.Take the angel as the starting point for BFS
Title: Yes, there are n puddles, with initial water, and amount of water. When the sum of water in a puddle is greater than the amount, the excess water is evenly divided between the puddles connected to the puddle, which is the direction between the puddle and the puddle.The topic is then given the first to add Y water to the X puddle, and finally to query how much water is present in the Z Puddle.Very well understood, mainly is the implementation of BFS
UVA 11624 fire! Topic: J Work in the Maze, one day The Maze fire, the fire has many places. Every second, the fire will spread to four directions, J will also move to four directions, asked J can run out, to output him to run out of the shortest time, otherwise output "impossible" problem-solving ideas: first to carry out a BFS, find every point of flame spread to the shortest time of the place. Then, according to the "Fire map", the path of J is
The t_t + + operator is not the same as +1. (i+1)%4 with parentheses. The BFS function is a bool type, forgetting to return false when the case. Oh.... Debug is going to cry ...DESCRIPTION:The least steps. Make all the pieces on the board black or white. Odd number of times is equivalent to 1 times. An even number of times is equal to not turning.BFS is used to solve the optimal problem. It is mainly used to find the shortest path from the initial sta
-bit primes a B is asked to change from a to B at least several times.The requirement for transformation is that only one number can be changed at a time, and the four-digit number that the intermediate process obtains must also be prime.Because it is mentioned that the minimum number of transformations, it is easy to think of BFS,BFS first search must be the shortest steps.First, hit a prime list.Then writ
was 3 because there is both horizontal steps and a vertical one. Our goal are to do the length of the shortest path to be 2.5. That's why we had to "stretch" the vertical dimension of the maze by a percentage value less than 100. In this case it is 50% which actually changes the vertical distance between both cells to 0.5. Test Instructions: gives a graph that marks the start and end points, and a telescopic transformation of the longitudinal axis so that the shortest path from the starting po
Topic Portal1 /*2 BFS: three-dimensional BFS, coordinates plus the number of steps, can walk a point when this place in the number of steps can not fall. Because the statue will fall in at most 8 steps,3 just make it through this time and win, or lose4 */5#include 6#include 7#include 8#include 9#include Ten using namespacestd; One A Const intMAXN =Ten; - Const intINF =0x3f3f3f3f; - structpoint{ the int
Output(0, 0) (1, 0) (2, 0) (2, 1) (2, 2) (2, 3) (2, 4) (3, 4) (4, 4)To record a path, you only need to maintain an array that records the leading node of the point that joins the queue (that is, from which point the point is reached).And then reverse the path from the endpoint, save it with an array,Finally, the output of the array that records the results is reversed.#include #include #include using namespace Std;const int maxn=5;int MAZE[MAXN][MAXN];int dx[4]={0,0,1,-1};int dy[4]={1,-1,0,0};s
one road between any and Settlemen Ts. It is also guaranteed, the road network is connected. Given pairwise different integerss,F, andR, which is the numbers of the settlements described above.OutputIn the-line output the required distance.Sample Input
input
Output
7 71 22 42 53 44 65 66 71 7 3
2
Notesin the sample the caravan may follow either the route 1-2-4-6-7 or the route 1-2-5-6-7. In the first case the robbers lay a ambush in settlement
Test instructions: Give n points, M edge, each edge is painted with a color, the shortest path from node 1 to node n, if there are more than one shortest path, the need to pass the color of the edge of the dictionary order minimumPurple Book of Ideas: The first time from the end of the BFS, to find out the minimum distance between each node to the end point,The second BFS moves from the starting point along
/* Reading this question from yesterday afternoon until now, I have done a similar continuous reading problem, which is similar to this question,I wrote it according to that idea. I found it step by step. I was dizzy and failed to write BFS into the storm. In the morning, ask the cool about BFs.Do not search for the number of steps. Search for the number of straight lines directly. It means a road goes to the head and does not hit the south wall.^_^ )
| Help center | welcome, liang530, office call: 0738-8371676
HomepageYou are welcome to visit the Program Design Competition website of Hunan Institute of humanities and technology. We are striving to do better!
System Homepage| Help |Full-text search
Discussion board| Forum list
Question list| Upload questions| Submission status
The competition is over|Reserve a competition |Current competition
User ranking| Modify personal information| User Registration
Data Structure: Figure 2 (
Question Link: Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1242
question .
solution :
If there is no special point, it is common BFs.
Because of the intervention of special points, a point may arrive in different ways, so the priority queue is used. For a point, the method used to retrieve the first point must be optimal.
At the same time, the use of priority queue also provides a pruning for the BFS
disappear (I. E ., in this turn ). well, given the description of a map, the positions of your tank and the target, how many turns will you take at least to arrive there?
Input The input consists of several test cases. the first line of each test case contains two integers m and n (2 Output For each test case, please output the turns you take at least in a separate line. If you can't arrive at the target, output "-1" instead.
Sample Input
3 4YBEBEERESSTE0 0
Sample output
8
Source Poj mon
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.