case contains the integers N and M indicate the size of the board. Then goes-N line, each line with M character shows the board. "#" indicates the grass. You can assume this there is at least one grid which are consisting of grass in the board.1 OutputFor each case, output of the case number first, if they can play the more special (Hentai) game (fire all the grass), output The minimal time they need to wait after they set fire, otherwise just output-1. See the sample, input and output for more
HDU-5040-Instrusive (BFS + priority queue), instrusiveProblem DescriptionThe legendary mercenary Solid Matt gets a classic mission: infiltrate a military base.The military base can be seen as an N * N grid. Matt's target is in one of the grids and Matt is now in another grid.In normal case, Matt can move from a grid to one of the four neighbor grids in a second. But this mission is not easy.Around the military base there are fences, Matt can't get out
Use STL to implement DFS/BFS Algorithms
-- Check the duplicate statusA few days ago, some netizens commented that my use of "Shen" and "Shen Kuan" is a second-class word. The correct statement should be "depth first" and "breadth first ". Although attitudes and words are a bit unacceptable, the comments are a bit reasonable. To be honest, I do not remember where I learned the first word "Shen" and "Shen Kuan", but I can be certain that I cannot create
Label: ACM algorithm DP Algorithm
Poj 1252 euro efficiency (BFS or full backpack)
Http://poj.org/problem? Id = 1252
Question:
There are 6 currencies in which their nominal values are 1, V2, V3, V4, V5, and v6, and their maximum values are less than 100. the minimum value is always 1 (that is, V1 ). the problem now is that you need to use up the six currencies in a small amount.StructureThe amount of money with a nominal value of 1 to 100. How
DescriptionProblem B-BFS (Binary Fibonacci string)
We are familiar with the Fibonacci sequence (1, 1, 2, 3, 5, 8,...). What if we define a similar sequence for strings? Sounds interesting? Let's see.
We define the follwing sequence:
BFS (0) = 0BFS (1) = 1 (here "0" and "1" are strings, not simply the numerical digit, 0 or 1)
For All (n> 1)BFS (n) =
can let them meet.Sample Input4 4y.#@.....#. @.. M4 4y.#@.....#. @#. M5 5[email protected].#....#...@. m.#...#Sample Output668866AuthoryifenfeiThe age of Source struggleRecommendyifenfei Test instructions: Y and M two people agreed to meet at @, ask two people add up the shortest time is how much analysis: BFS does not need to each @ BFS, with Y and M as the starting point for
Hdu 4230 bfs + memory-based search
The number of steps from the start point to the end point;
Mark indicates the minimum number of steps corresponding to each vertex in each direction;
Num indicates planting trees;
Search for the question.
#include
#include
#include
#include
using namespace std
;#define INF 0x3f3f3f3f
struct node
{ int x
,y
,step
; int d
;}a
,b
;int n
In the basic algorithm of graph, the first need to contact is the graph traversal algorithm, according to the order of access nodes, can be divided into depth-first search (DFS)和Breadth First Search (BFS)。 DFS (deep first search) algorithmDepth-first-searchDepth-first algorithm is an algorithm for traversing or searching a tree or graph. Traverse the tree's nodes along the depth of the tree, searching the branches of the tree as deep as possible.When
Hdoj 1242 Rescue (BFS)
Rescue
Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1242
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission (s): 18962 Accepted Submission (s): 6771
Problem Description Angel was caught by the MOLIGPY! He was put in prison by Moligpy. The prison is described as a N * M (N, M
Angel's friends want to save Angel. their task is: approach Angel. we assume that "approach Angel" is t
[2], 2, 3, 1, 0
LEFT SearchDirection [3], 3, 0, 1, 2
It is easy to determine the search direction and Search Start Point Based on the initial direction, but how can we determine the next direction after the search.
If selected, SearchDirection [0]-> corresponds to the last LEFT
SearchDirection [1]-> UP
SearchDirection [2]-> RIGHT
SearchDirection [3]-> DOWN
Assume that the initial direction is d represented by enum {UP, RIGHT, DOWN, LEFT}, and the selected searchction ction is I, then the final
Breadth-First traversalBreadth-first traversal is a graph traversal method that is often seen and common, with the exception of BFS and DFS, which is the depth-first traversal method. I'll write it in my next blog post.Traversal processI believe every person who looks at this blog will be able to read and understand the adjacency list storage diagram.Do not understand the people. Please learn the storage method first. In my previous blog.Portal: Diagr
A classic BFS example to illustrate the concept of BFS
Zoj2913-bus Pass Test instructions: Find a center area, so that center to all bus lines shortest, equidistant center is the output ID of the smallest. The main point: the classic BFS, by the bus line at most only through the 10*20 zone, and the total area of up to 10^5, so should be from the bus line t
Given a 2D board containing ‘X‘ ‘O‘ and, capture all regions surrounded by ‘X‘ .A region was captured by flipping all ‘O‘ s into ‘X‘ s-surrounded region.For example,x x x xx o o xx x o xx o x xAfter running your function, the board should is:x x x xx x x xx x x xx O x xThe problem: The test data card is very strict. Started with the DFS burst stack, and later changed to BFS and timed out. Finally improved the next: Check the edge of There is no ' O ',
If this problem can constitute the area of non-interference, its composition of the figure is actually Hamilton Road, So if can be observed directly into the existence of Hamilton Road proof, even if not observed, I believe that Acmer can also be converted into BFS problem, this problem is a good graph theory, it is helpful to examine the basic skills of their own graph theory.
Wireless broadcast (broadcast)
DescriptionA broadcasting compa
0Checkerboard problem, change the color of a child, the child and the child around the four positions (left and right) of the child to change color, to find the minimum number of changes.Most of this type of problem should be solved with state compression + brute force search. It's not quite reasonable to find the rules purely.1) The first method, state compression after the BFS violent search. Because the chessboard is small, there are only 16 square
Topic Links:Lightoj 1174-commandosTitle Description:There is an army adhering to do the best slogan, ready to destroy the enemy barracks. They plan to put a bomb in every enemy barracks. There are plenty of soldiers in the barracks, every soldier can carry enough bombs, ask the army to complete the task at least time? (If the soldiers were to put bombs in the enemy tent, the enemy would not defend them.) is the enemy a pig? Is this a fight with a pig? )Problem Solving Ideas:Water problem, the
Http://ac.jobdu.com/problem.php? Id = 1335
There is another question, similar
Http://ac.jobdu.com/problem.php? Id = 1365
We recommend that you use BFS for ease of implementation.
Description:
Sun's school holds a computer festival every year. This year's Computer Festival has a new interesting competition project called Chuang maze.Sun's roommate designed the maze for the Computer Festival, So Sun asked Sun
/*
Question:
Calculate the minimum time from (0, 0) to (4, 4) path
Analysis:
This is a pure BFS question. However, to print the path, you can use an array to record the previous coordinate of the current coordinate,
Because BFS constructs a BFS optimal Spanning Tree, each node's parent node is unique.
ReferenceAlgorithmIntroduction...
*/
# Include
For non-linear structures, traversal will first become a problem. Like binary tree traversal, a graph also has two types: Deep preference search (DFS) and breadth preference search (BFS. The difference is that each vertex in the graph does not have the relationship between the ancestor and the descendant. Therefore, the pre-order, middle-order, and post-order are no longer meaningful. Similar to the traversal of a binary tree, you can easily complete
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.