groups involved in the search together. That's, if the original group walks five steps, then splits into both groups each walking three steps, the total distance Is 11=5+3+3.InputOn the first line of input there are one integer, N OutputFor every test case, output one line containing the minimal cost of a succesful search of the maze leaving no aliens alive .Sample Input5##### #A #a### # a# #S ###### #7 7##### #AAA # # # # # # # # # # # #AAA a## Sample Output811The main idea: a figure, in
Title Link: http://poj.org/problem?id=3278Test instructionsOn a number (0 ~ 100000), give you farmer J's position n, and the position of the Bull Cow K, the farmer has three ways of moving: Move left one step (X-1,x is the current position), move right one step (x + 1), move right 2*x step (2 * x), ask the farmer to move at least how many steps can catch up Cows are not moving in situ.Ideas:Since the question is how many steps to move at least, the most easily thought of is violence, assuming th
Getting Started BFS, for the first time, partly borrowed from the great God's#include #include#includeusing namespacestd;inta[5][5];BOOLvisit[5][5];intdx[4]={0,1,0,-1};//Four directions: 0 for right, 1 for lower, 2 for left and 3 for upperintdy[4]={1,0,-1,0};structnode{intx; inty; intS//Path Length intdirec[ -];//Record Direction}node,next;BOOLJudgeintXinty) { if(x0|| X>4|| y0|| Y>4) return true; if(visit[x][y]==true|| a[x][y]==1)
http://www.luogu.org/problem/show?pid=1141To ask questions, the size of the sub-connected block of undirected graphs is sought.Direct BFS, read a search one, over 60;100% points 1,000,000 points, 100,000 queries, is obviously memory.I was weak, and I started out. The number group records the coordinates of the first point of each point belonging to the connected block, and then writes a bunch of them.Later asked a great God, like the mist to see the s
, 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
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.