Poj 3278 Catch That Cow (bfs search), pojbfsCatch That Cow
Time Limit:2000 MS
Memory Limit:65536 K
Total Submissions:46715
Accepted:14673
Description
Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a pointN(0 ≤N≤ 100,000) on a number line and the cow is at a pointK(0 ≤K≤ 100,000) on the same number line. Farmer John has two modes of transportation: w
in the dictionary and get a complete picture of the structure. According to the requirements of the topic, equivalent to the shortest path of one vertex to another in this graph, we usually use breadth first. This problem, we can only use the simplest way to do, each change the word of a letter, and then gradually search, the shortest path, the minimum depth of the tree with BFS most suitable. Take a look at the time
The word adjacent t
Reprint please indicate the source, thank you http://blog.csdn.net/ACM_cxlove? Viewmode = contents by --- cxlove
The first write bidirectional BFs.
Bidirectional BFS searches from the start and end points. If the intersection points appear, the target point is reachable. This requirement is to arrive within eight steps. Each step has 16 states, and the complexity of 16 ^ 8 is still very high. Because the st
statuses of the magic board, please give the transformation steps from the initial state to the smallest number of changes in the object state. If there are multiple conversion schemes, take the smallest Lexicographic Order.
Each group of input test data includes two rows, representing the initial and object states of the magic board.
Output converts the output of each group of test data to meet the requirements of the question.
Sample Input
12345678172453681234567882754631
Sample output
CAC
Au
one. I used brute force to solve the question. I always decided whether I could divide the question by two. Then I also wanted to use brute force at the beginning, but later I do some of the circumstances can not be considered, this question is also more than the copy of the http://blog.csdn.net/whjkm/article/details/26985421 (the previous question of The Link), and then carefully read the question, there is still a big difference with that question. The simple question is that it starts from 0
Question Link: Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1180
Theme: There are a bunch of stairs in the maze, and the stairs change horizontally and vertically. These stairs change to the opposite state at an odd number of times, and the next point in the forward direction will be reached by the way through the stairs (skip the stairs ).
At the same time, you can wait in the same place and ask the minimum time to reach the destination.
Solutions:
An interesting question.
Or
Tags: ACM Wang Guiping Graph Theory
Find a center in all cities to meet the maximum and minimum output distance between the center and all bus stations and the center with the minimum and minimum distance numbers.
The most basic BFS for each bus station BFS dis [I] indicates the number of I to the maximum distance of all bus stations BFS after all sites dis [I] m
Question: Give a map. Sun Wukong (k) saves Tang Monk (T). The map's indicates a snake. It takes up to five dead snakes a minute, '1 '~ 'M' indicates M keys (M
Solution: BFs. Each node maintains four values:
X, Y: Current Coordinate
Key: Key keys have been collected.
Step: How many steps have been taken
S: The access status of the snake. (2 ^ 5 indicates that the number of snakes has been killed. If 1 is set to 1, the snake has been killed)
Then, take
. Space is the place where I can go. # No, It is around # Note: it can only be separated in S or a. the space area cannot be split.Algorithm: min spanning tree + BFS idea: Build a graph and convert it to Min spanning tree, then directly apply the prime or Kruskal TemplateBecause only the S and a parts can be separated, S and a are the same, use BFs to traverse S and each A to find the shortest distance betw
Test instructions to give two four-bit primes A, B, each time only a certain number of a can be modified to make it another four-bit prime, ask at least how many operations, can make a change to B. BFS search can be done directly1#include 2 using namespacestd;3 4 BOOLIsPrime (intN) {//Prime Judgment5 if(n = =2|| n = =3)return true;6 Else{7 intK = sqrt (n) +1;8 for(inti =2; I ){9 if(n% i = =0)return false;Ten
: Bessie can pass through the open space 1: Inaccessible areas due to various reasons 2: Betsy's position now 3: the Knights ' location 4: The land output of the shrubs which Bessie needed Outputs a positive integer d, that is, how many days it will take for Bessie to finish the task given by the Knights. Sample INPUT8 44 1 0 0 0 0 1 00 0 0 1 0 1 0 00 2 1 1 3 0 4 00 0 0 4 1 1 1 0INPUT DETAILS:Width=8, height=4. Bessie starts on the third row, only a few squares awayFrom the Knights.Sample Outp
Author: July January 1, 2011
---------------------------------
My reference: Introduction to AlgorithmsMy statement: Personal Original, reprinted please indicate the source.
OK.
There are many articles on such BFS and DFS algorithms on the Internet. 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 search of graphs.
---------------------
We started wi
HDU-2259-Continuous Same Game (2) (BFS + DFS + simulation), dfsbfsProblem DescriptionAfter repeated attempts, LL finds the greedy strategy is very awful in practice. even there is no apparent evidence to proof it is better than a random one. so he has to drop this strategy and try to discover a better one.InputThere are 100 test cases. each test case begins with two integers n, m (5 OutputFor each test case, first output a single line containing the n
Link: zoj 3820 building fire stations
Given a tree, select two gas stations and ask the minimum value of the distance between all points and the gas station, and output a method of gas station establishment.
Solution: The second distance is used to determine the complexity of the function is O (n). The complexity should be O (nlogn). Even if the constant coefficient is too large, the system ran 4.5 S, it's also drunk.The judgment function performs BFS
Http://poj.org/problem? Id = 2965
The 16 locations have two states, which are represented by a 16-bit binary. Beg is obtained by bitwise OR calculation. In BFs, use a hexadecimal number that contains only 0, 1 to implement the flip operation.
The rest is simply BFs.
Code:# Include # Include # Include Using namespace STD;
Int dir [16] = {0x111f, 0x222f, 0x444f, 0x888f,
0x11f1, 0x22f2, 0x44f4, 0x88f8,
0x1f11,
DFS uses recursion and does not have to use redundant data structures for simplicity. But pay attention to pruning.
BFS uses queues to find the optimal solution. The optimal solution can always be found, and pruning is also required in some cases.
These two methods are used according to the specific problem.
For example, both DFS and BFS can be used to solve the problem.
This was not the case at the beginning, and the running result was correct, but the memory was too large. Baidu used other people's methods. In fact, they only stored the values below, so I opened an dis [] [] [] array on the basis of the original one. To be honest, this is the first time I used a 3D array, I just stored the following and submitted the AC! Heheh ·······
I used to find a KFC and use BFS once, so the memory is too large. It seems that t
format is as follows:Line 1th: Two positive integers, n,m. 1≤n,m≤50, which represents the size of a small town.Next there are n lines, each with a M-lowercase letter, representing the town's map.OutputA total of k rows, each row corresponding to a set of data. At least how many pumps must be bought in order to get all the water out of the grid.Sample input9CBABCBABCCBABCBABCCBABCBABCCBABCBABC 5CCCCCCBBBCCBABCCBBBCCCCCC4Sample output12"Analysis" I wrote in B
DescriptionYou are given the pots of the volume of A and B liters respectively. The following operations can be performed:Fill (i) Fill the pot I (1≤i≤2) from the tap;DROP (i) empty the pot I to the drain;Pour (i,j) pour from pot I to pot J; After this operation either the pot J was full (and there could be some water left in the pot I), or the pot I was empty (and All its contents has been moved to the pot J).Write a program to find the shortest possible sequence of these operations that'll yie
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.