describes a stick, wherein the I+1 Act Two integer Ai,bi, which represents the number of two balls connected by the root of the I stick.For 20% of data, meet nFor 50% of data, meet nFor 100% of data, meet NLittle hi Tip: Those with array storage tree edge remember to open twice times the size Oh!OutputFor each set of test data, output an integer ans, which indicates the distance between the two nodes farthest from the given tree.
Sample input
81 21 31 44 53 66 77
BFS, bi-directional BFS and A * Table of Contents 1. BFS 2. Bidirectional BFS 3. A * algorithm
It is useless to say no practice, we from the well-known POJ 2243 this topic: The main idea: given a starting point and an end, according to the Knight's Way (Go Day), from the beginning to the end of the minimum move how man
Figure exercise-bfs-the shortest number of steps from the start to the target point
Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^
Title description in the ancient Warcraft legend, there are two legions, one called the Scourge, one called Janissary. In their area, there are n passes, numbered 1. N, there is a channel connection between some passes. Among them, the Legion was in the 1th, and the Scourge was in the N
Topic Link: http://acm.hdu.edu.cn/showproblem.php?pid=1195, two-way BFS or direct BFS can also be too.In fact, this problem is only one-way BFS can be over, but in order to practice the algorithm, so still use a two-way bfs to write.
Algorithm: First preprocessing, from 1111 to 9999 of all points of the composit
Main TopicPush box game basic gameplay, to push the box to the destination of the minimum number of push (not the total number of people moving) move the path.Problem Analysis to find the shortest path search problem, using BFS. Note that the problem is driven by the least number of times, so the box movement as a state, the box to move the minimum number of times to reach the destination path, and then on the path of the inflection point on the basis
fastest one, finally comfortable, asked the other people's writing, the magic of pure BFS. Although not my optimization after the fast, but the 5K code is still a bit ... Not much to say, or to see the subject. Test instructions is, a person has two fire, he will burn down the whole playground of all grass, fire can only like four directions, along the haystack spread. Ask, whether can burn out, the minimum time is how much. /*/ /* /here is the firs
Link: knight moves
It is not difficult to study two-way BFs. Like common BFs, two-way BFS only searches at the same time from the start and end points, reducing the search time.
When the two search routes meet, the process ends.
It seems that one year of Baidu's recruitment test is two-way BFS ....
Next, compare the
Label: style blog HTTP color Io OS AR for strong
Link: Rescue
The progress has dropped too much. I always complain that the progress is slower than others... Why don't you try to change it ....
I thought it was a water question. I wanted to try it out. Later I found that it was not a simple search question. BFS was definitely doing something wrong... Later, I found that there were pitfalls in the question.
It is the shortest distance from R to A, ".
Use BFS to solve the Maze problem and BFS to solve the Maze problemIn an n * n matrix, the path starts from the origin point (0, 0) to the end point (n-1, n-1). The path can only go in the upper, lower, and left directions, but only in the given matrix, calculate the minimum number of steps. N * n is the 01 matrix. 0 indicates that the grid has no obstacle. 1 indicates that there is an obstacle. Int mazeArr
HDU1240-detailed explanation of the subject meaning (3D BFS), hdu1240-bfs
Enter start n to indicate that the number of layers of the cube is N, and each layer is an NxN square .. It is actually a cube of NxNxN, Which is input layer by layer.
After entering the cube, enter the coordinates of the start and end points.
The output is the number of steps that output N first and then the shortest path. If the des
Test instructions: Two-dimensional matrix, the guards from the outside to the inside to put two prisoners, asked the middle of the door to open the minimum number of times.Analysis:This question from the outside, so long as the matrix edge can go to the point (except the point of the wall) can be used as a starting point, there are two end points, so the direct lifting point of the search is not feasible. The practice is to use three times BFS, respec
Link: Rescue
The progress has dropped too much. I always complain that the progress is slower than others... Why don't you try to change it ....
I thought it was a water question. I wanted to try it out. Later I found that it was not a simple search question. BFS was definitely doing something wrong... Later, I found that there were pitfalls in the question.
It is the shortest distance from R to A, "." is equivalent to 1, and "X" is equivalent to 2.
How to achieve breadth-first traversal (BFS) and breadth-bfs
BFS process:
1. Access vertex V and Mark V as accessed
Ii. vertex V entry queue
3. If the queue is not empty, execute the command; otherwise, the algorithm ends.
4. Obtain the right vertex u in the output queue. If the vertex is not accessed, access the vertex and mark it as accessed.
5. Find the first
/*
/*The method draws on the hdoj Forum and has not dealt with any questions that can be taken back. Therefore, it is very tricky to deal,The memory burst for the first time. For the output is-1, I initially considered a problem, but I don't know how to solve it.Later, I came to the Forum and thought it was because of the endless loop caused by my code.The deformation of BFS really makes people feel a little bit ..*/# Include # Include # Include # In
Hdu1254 push box (bfs + bfs)Push boxTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission (s): 6386 Accepted Submission (s): 1825Problem Description is a classic game. today we are going to play a simple version. in a M * N room, there is a box and a porter. the porter's job is to push the box to the specified position. Note that the Porter can only push the box bu
The previous article wrote the Dfs adjacency matrix and adjacency table, and this one writes about the BFSFirst about BFS, full name Breadth First search, no backtracking and probing, step by step, using queue implementationAccesses the current vertex v first, then accesses each of the inaccessible adjacency vertices of V, and then accesses the inaccessible adjacency vertices of each of the adjacent vertices of V at a timeThe code is implemented as fo
home from the a area. Now Ikki want to know how many different routes to go home.
Input
The first behavior of each group of data is an integer n (2
Output
The total number of different routes for each set of data output (less than 2^63).
Sample Input
31 1 11 1 11 1 131 2 31 2 31 2 3
Sample Output
61
Author
Eric @hrbust
Why do Chinese questions have
Figure exercise-bfs-the shortest number of steps from the start to the target point
Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^
Title description in the ancient Warcraft legend, there are two legions, one called the Scourge, one called Janissary. In their area, there are n passes, numbered 1. N, there is a channel connection between some passes. Among them, the Legion was in the 1th, and the Scourge was in the N
walk on it.1:the area contains nothing, Ignatius can walk on it.2:ignatius ' start position, Ignatius starts his escape from this position.3:the exit of the Labyrinth, Ignatius ' target position.4:the area contains a bomb-reset-equipment, Ignatius can delay the exploding time by walking to these areas.Outputfor Each test case, if Ignatius can get out of the labyrinth, you should output the minimum time he needs, else you should just output-1.Sample InputSample Output4-113I do not want to explai
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.