Document directory
This topic includes the door and key on the basic BFs. You need to find all the keys to open the door.
1. First count the number of keys of each type, and then write down the location of the door.
3. In case of a door, check whether the key is correct. If yes, enter the team and Mark accessed. If not, Mark accessed.
4. Follow the normal BFS for others.
Question connection: http://
The first thing to illustrate is that the BFS algorithm (breadth-first algorithm) is also an embodiment of the enumeration idea, itself is not very efficient, when the size of the data is very small can be a test. Second, many people may have such doubts, the use of the search algorithm, the choice of Dfs or BFS, bloggers think for the shortest short-circuit search is all right, the data scale is small, wid
Breadth-First search (BFS) (with examples) questions arise:Isenbaev is a foreign Daniel.Now there are many people who want to take part in ACM ICPC.There are altogether n groups, each group of 3 persons. All 3 people in the same group are teammates.Everyone wants to know what the minimum distance is from Daniel.Daniel's minimum distance with himself is of course 0. The minimum distance between Daniel's teammates and Daniel is 1. Daniel's teammate's te
SDUT 1124-leap wilderness-3D BFS
Leap wilderness
Time Limit: 5000 ms Memory limit: 65536 K any questions? Click Here ^_^
After the brave fario completed the task, he was quickly retreating to his own base. However, because there is a large group of follow-up troops behind it, fario should return to the base as soon as possible, or else he will be caught by the enemy.
Finally, fario came to the last stop: The field of telachel, where he can ret
case, the print one line saying "to get from XX to YY takes N Knight moves."Sample InputE2 E4A1 b2b2 c3a1 h8a1 h7h8 a1b1 c3f6 f6Sample Output to get from E2 to E4 takes 2 Knight moves. To get from A1 to B2 takes 4 knight moves. To get from B2 to C3 takes 2 knight moves. To get from A1 to H8 takes 6 knight moves. To get from A1 to H7 takes 5 knight moves. To get from H8 to A1 takes 6 knight moves. To get from B1 to C3 takes 1 Knight moves. To get from F6 to F6 takes 0 knight moves.Code:/*Simple
Topic Link: http://acm.hdu.edu.cn/showproblem.php?pid=1430, a better problem.This problem to use a lot of knowledge, Cantor expansion, BFS, the pre-treatment of the table to use one by one mapping, done to benefit.In fact, this problem can also be used to write two-way BFS, thinking has already been, a few days to write.This article continues to update.
First, the search section: For each state of th
POJ 3083 dfs+bfs+ Analog Children of the Candy Corn
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 10564
Accepted: 4539
DescriptionThe Cornfield Maze is a popular Halloween treat. Visitors is shown the entrance and must wander through the maze facing zombies, chainsaw-wielding psychopaths, hippies, a nd other terrors on their quest to find the exit.One popular maze-walking str
The topic is really simple, the idea is easy to come out, the difficulty lies in the record of the obstacle, is the BFS Maze question very classic topic.
Poj2935-basic Wall MazeTest instructions: 6*6 chessboard, there are three walls, the shortest path from a given initial point to a given endpoint, the output of one of the shortest paths in the same length. Problems: BFS will not say, for the record
. Sample InputInput5 R 8 U 9 L 9 D 8 L 2Output101Input7 R Ten D 2 L 7 U 9 d 2 R 3 d 10Output52Test instructions: There is a very large field (you when it is infinite), each size is 1m*1m, the protagonist to spray insecticide, he starts from the beginning, you can go toward the U (Upper), D (lower), L (left), R (right) Four directions to a certain distance, then this section of the road is sprayed with pesticides,Give n operations, enter a character and number each time, respectively, represe
test case, your program should output a single integer, standing for the minimal time needed. If Such a number does no exist, you should output a line containing "Poor ANGEL have to stay in the prison all he life."Sample Input7 8#.#####.#.a#. r.#. #x ..... #.##...##...#..............Sample Output13AuthorCHEN, XueSourceZOJ Monthly, October 2003recommendEddy | We have carefully selected several similar problems for you:1240 1016 1010 1072 1253/**/The first time to write BFSMain topic:1. In the ma
of the battery needed for his prison break.
Inputinput contains multiple test cases, ended by 0 0. for each test case, the first line contains two integer numbers N and M showing the size of the jail. next n lines consist of m capital letters each, which stands for the description of the jail. you can assume that 1 Outputfor each test case, output one integer in a line, representing the minimum size of the battery Micheal #1 needs. If Micheal #1 can't escape, output-1.
Sample input5 5
Gd
4. teach you a thorough understanding: BFS and DFS preferred searchAlgorithm
Author: July January 1, 2011
---------------------------------
My reference: Introduction to AlgorithmsMy statement: Personal Original, reprinted please indicate the source.
OK.
Repeat the internet.Article, Many. However, there is no such reason.After reading this article, I think,You will have a thorough understanding of the breadth-first search and depth-first s
Magic plate problem, a classic kang expansion open +bfs problem, for the sake of convenience, I use String class to represent the string, which was seldom used in the string class (because it is not efficient, and relative to the char array related functions are relatively familiar), So there are a lot of things that are easy to overlook.
For Kang expansion to open not very familiar with the department can first see a blog: http://blog.csdn.net/
. It is guaranteed, the upper-left and the lower-right cells of both labyrinths are free.OutputOutput«yes»if there exists such a path from the upper-left to the Lower-right cell that's the shortest for both Labyrin Ths. Otherwise output«no»Sample Input3 5......#.#...........#.#.#.....Sample OutputYESHINTTest instructionsAsk you if there is a road, in two mazes are legal, and are the shortest way?Exercises3 times BFS, first
Analysis:This is called the Maze Search to find the shortest problem, and the output to include the path, is a typical search question it. The problem I used is BFS search, the first need to establish a structure to store the coordinates to each location and the total time spent, using BFS of course to use the priority queue, in this queue, spend less time on the team head, also need to build a structure t
GoTwo-way BFS (http://www.cppblog.com/Yuan/archive/2011/02/23/140553.aspx)If the target is also known, using two-way BFS can greatly improve the speedOne-way, is the extension of the B^len.Bidirectional words, 2*b^ (LEN/2) a lot faster, especially when the branch factor B is largeAs for implementation, some of the online practice is to use two queues, alternating nodes to search for x, such as the followin
Title AddressBeginner BFS, the first time to use BFS to do the problem. The problem is a basic BFS model, which requires a little attention to +1 of the guard time, and the shortest time rather than the number of steps.1#include 2#include 3#include 4 #defineS 2055 #defineINF 1000006 using namespacestd;7 structLo//build a structure, store point coordinates, and so
Breadth FirstDescription:Ali trapped in the maze, Snoopy to save him, Snoopy can go up, down, left, right four directions, each walk step (lattice) will drink a bottle of more power. Now give it a maze map. May I ask: how many bottles of Snoopy do you need at least to get out of the maze?Input:First enter a number T, indicating the number of test data, the following input is the T maze, each maze input should contain the following data, enter the size of the maze of N (nOutput:The output require
Question Link
Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1548
The number of elevators on each layer. For example, the number of floors on the N layer is K,
Therefore, this layer can only be of the upper or lower K layers, but cannot be lower than or higher than N layers,
Given the start point and end point, the minimum number of keys required
My idea: You can use BFS or dijsktra)
BFS
AC code
# Include
of mod 2 obtains each bit of K (0 or 1)What about it?
The answer is yes.
First, we useSame modulus TheoremOptimize the method for getting the remainder
(A * B) % N = (a % N * B % N) % N
(A + B) % N = (a % N + B % N) % N
Code1:
1 # Include 2 # Include 3 # Include String . H> 4 # Include 5 Using Namespace STD; 6 7 Int MoD [ 600000 ]; 8 Int Res [ 200 ]; 9 10 Int Main () 11 { 12 Int N; 13 While (~ Scanf ( " % D " , N ) N) 14 { 15 MoD [ 1
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.