Very simple BFS.
WA reason: or because rqnoj data input with GetChar () seems to be wrong, changed to scanf ("%s"), and then because did not notice starting from 1 ...
scanf ("%s", Map[i]);
Change into
scanf ("%s", map[i][1]);It's AC.
This simple search question can not be once AC is the reflection of the following ...
#define _crt_secure_no_warnings #include
to the edges of the vertex. The vertex VJ adjacent to VI are linked to a single linked list called VI adjacency list. Each node in the adjacency list is composed of two domains: one is the neighboring point Domain (Adjvex), the ordinal number J (can be the subscript of the array unit of vertex VJ in the vertex table) used to store the vertex VJ adjacent to VI; the second is the chain field (next), which links the nodes in the adjacency list. The specific procedures are implemented as follows:
disappear (i.e., in this turn). Well, given the description of a maps, the positions of your tank and the target, how many turns would you take at least to Arrive there?
Input the input consists of several test cases. The first line of all test case contains, integers m and n (2
Output for each test case, please output the turns to least in a separate line. If you can ' t arrive at the target, output "-1" instead.
Sample Input
3 4
ybeb
EERE
sste
0 0
Sample Output
8Test instructions: How long
the target, how many turns would you take at least to Arrive there? Input
The input consists of several test cases. The first line of all test case contains, integers m and n (2 Output
For each test case, please output the turns to least in a separate line. If you can ' t arrive at the target, output "-1" instead.Sample Input
3 4YbebEERESste0 0Sample Output
8
title Link:http://poj.org/problem?id=2312 Test Instructions
Calculate the shortest time from ' Y ' to ' t ', where ' S ' and ' R ' cann
target, how many turns would you take at least to Arrive there? Input
The input consists of several test cases. The first line of all test case contains, integers m and n (2 Output
For each test case, please output the turns to least in a separate line. If you can ' t arrive at the target, output "-1" instead.Sample Input
3 4YbebEERESste0 0Sample Output
8Source
POJ Monthly, Lu Xiao
Test Instructions:Give you a matrix of m rows n columns.Y represents the starting point, and T represents the en
description of a maps, the positions of your tank and the target, how many turns would you take at least to Arrive there?
Input the input consists of several test cases. The first line of all test case contains, integers m and n (2
Output for each test case, please output the turns to least in a separate line. If you can ' t arrive at the target, output "-1" instead.
Sample Input
3 4
ybeb
EERE
sste
0 0
Sample Output
8
Source
POJ Monthly, Lu Xiao
http://blog.csdn.net/furturerock/article/deta
here you should understand, there is no place to move the situation OH ~~~~~~)
Ideas:
Because there are a lot of points can be repeated, so we have to open three-dimensional array vis "" "" "to judge the weight, if one dimension is used to represent X, one dimension is used to represent Y, then the other one to indicate what. Of course, the number of steps to walk, but we do not know the total number of steps we can walk AH ~ so we here to the K to seek redundancy, as long as it is not 0, all i
Daily Punch-In (2/2)
Click to open linkMain topic:
A three-dimensional maze, given the starting point and end point, to find the shortest path.
PS: The length and width of the height are not more than 30
Idea 1:
First think of Dfs, only the first time to write three-dimensional DFS, feeling and two-dimensional nothing different.
#include
The first time I write the experience of the morning, cut a branch first. If the current TOT value has exceeded the previous optimal solution, then pass. Last
The storage structure of graphs
This article focuses on the depth-first search (DFS) and breadth-first search (BFS), so it is no longer to introduce the basic concepts of the graph too much, but to get a general idea of some of the common storage structures in the diagram below.
Adjacency Matrix
The adjacency matrix can be used both to store the graph without direction and to store the graph. In fact, the structure uses a two-dimensional array (adj
Topic links
POJ3278 Topic
Enter two number n,k (0≤\leqn,k≤\leq100000) to find at least a few legal operations from N to K. Legal actions include: + 1,-1, * *. Analysis
Consider each number of 0~100000 as a state, there are 3 ways to transfer the state, only from N start with the BFS expansion, see the expansion to K is the first layer, Time complexity O (3*100000). (similar to the shortest path in the maze)PS: This problem in OJ with g++ submitted on
calculation of time complexity is not very clear. My calculation of the time complexity of this problem is: Obviously the time complexity of the two for Loop is O ((m*n) ^2) =10^4. Then calculate the time complexity of the BFS: obviously each layer has a for loop, the loop volume is 4, the maximum layer is diagonal, 10 layers, so the total complexity of 4^10, in the front of the complexity, obviously timed out. But this is not the case, we can think,
Dating with Girls (2)
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 2656 Accepted Submission (s): 741
Problem Description If You had solved the problem Dating with girls (1). I Think you can solve this problem too. This problem was also about dating with girls. Now you are in a maze and the girl you want to date with is also in the maze. If you can find the girl and then you can date with the girl. Else the girl would date with other boy
DFS uses recursive step-by-step heuristics to select the shortest path in all paths
Code:
0 is the road, 1 is the wall
#include
BFS Use the queue one layer at a time to take the shortest
Code:
#include
Print out Path
Input 0 for road, 1 for Wall, 5*5 map//from upper left corner to bottom right #include
Transmission DoorTest instructions: Is given a starting point and an end point, each can go to four directions up to the K-step, each walk spent a second, asked to go to the end of the minimum number of seconds required.Idea: Direct BFS will definitely t, we need to add a few pruning, one is when we go to some point, the point has been reached, and at this time than from the current point of time to go to this point is shorter, then do not go, because
1 1 1 1 1 0 31 1 1 1 1 1 1 11 1 1 1 1 1 1 10 0
Sample Output
4-11320-1
-1
Test instructions: On a n*m map, there are 5 numbers. 0 means not to walk here, 1 means to go here, 3 is the Ant's Cave, 2 is where the ant starts to walk, and 4 says there is food here. An ant to go home, it initially only 6HP, and each step will be reduced by one, when HP is 0 o'clock will die, when it arrives at the food can be restored full hp and the food can be used indefinitely. Ask ants at least how many steps to
Article title: BFS introduction, the Fast Future of Linux desktop ?. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
As in the past, we are still compiling the new Linux kernel, a required course for accelerating the Linux system. The encounter with Linux kernel BFS is f
Give a maximum 16x16 maze map and up to 3 ghost start and target locations, so that at least a few rounds of movement can make three ghost reach the target location. Each round of movement, each ghost can take one step, can also stay in place, it is important to note that any two ghost can not be in the same position, so also can not appear any two ghost to wear, that is, the original is AB, after the move is BA. Each maze diagram ' # ' denotes a wall, ' ' denotes a clearing, a lowercase letter
Defined:
The breadth-first algorithm (Breadth-first-search), or BFS, is a graph search arithmetic method. To put it simply,BFS is the node that traverses the tree from the root node, along the width of the tree, and if the target is found, the calculation terminates .
Algorithm Analysis:
BFS is a blind search method that is designed to systematically unfold and
I believe everyone in the tank wars has played it. This question was designed based on this game. Tanks must go from the starting point (Y) to the destination (T). tanks cannot go through the steel wall (S), river (R), or walk in the open space (E ), damage to the brick wall (B) when shooting a brick wall, it does not walk and takes a unit of time, it also takes a unit of time to move up when the open space. How long does it take for a tank to start from the start point to the destination? The o
Original question link: http://poj.org/problem? Id = 3278
Algorithm: BFS + queue + STL (C ++)
PS: getting started with BFs. I'm so glad to use BFs.
Catch that cow
Time limit:2000 ms
Memory limit:65536 K
Total submissions:32679
Accepted:10060
Description
Farmer John has been informed of the location of a fugitive cow and wants
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.