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 1072 1253 1372 1175#include Copyright NOTICE: This article for Bo Master original article, without Bo Master permission
This problem, simple BFS can be done. The approximate meaning of the topic is the shortest time from the r of the map to reach a.In the beginning, with the normal queue to do, the result of memory is super, the reason is N and M maximum 200; a normal queue wastes a lot of memory, so you should use a priority queue instead.The following is the code for AC:#include Hangzhou Electric acm1242--rescue~~bfs+ Priority queue
one step in one direction is feasible, then it is possible to determine whether this is the shortest. If yes, then press in - { - Lo t; int.x=x;t.y=y;t.time=hd.time+1; t.step=hd.step+1; - if(tem[x][y]=='x') t.time++;//if it's a guard, it's +1 hours. to if(T.time//there may be a shorter way to get here, but since each is put in a queue, it will continue from here . +{mintime[x][y]=T.time; - Q.push (t); the } * } $ }P
.
Outputfor each test case, your program shocould output a single integer, standing for the minimal time needed. if such a number does no exist, you showould output a line containing "Poor Angel has to stay in the prison all his life."
Sample Input
7 8#.#####.#.a#..r.#..#x.....#..#.##...##...#..............Sample output
13 because of the existence of a guard, it may not be a small time to first join the queue. If we want to output a small amount of time, we need to first deal with a small amount
Link: Rescue
The progress has dropped too much. I always complain that the progress is slower than others... Why don't you try to change it ....
I thought it was a water question. I wanted to try it out. Later I found that it was not a simple search question. BFS was definitely doing something wrong... Later, I found that there were pitfalls in the question.
It is the shortest distance from R to A, "." is equivalent to 1, and "X" is equivalent to 2.
Rescue
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)Total submission (s): 14966 accepted submission (s): 5425Problem descriptionangel 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 to get to the position where angel stays. when there's a guard in the grid, we mus
BFS problems.
Angel was in jail, and many of her friends were trying to save her.
# Indicates the wall,. indicates the road, X indicates the guard, and r indicates her friends.
Because there may be many friends, but there is only one angel, the Search Start Point is set to Angel. If you find a friend, you can go out.
It takes 1 to take a grid and 1 to kill the guard, but it cannot be added directly.
This is because
4 8axxxxxxr........................
If you add 2 directly, the answer is no
Pay attention to the word "each" in this question, so there may be multiple 'R', so it is relatively simple to search for the saved person.
The priority queue is unknown at the beginning, so the priority queue is wa at the beginning.
The operations of the priority queue are similar to those of the queue, but the front () function in the queue should be replaced by the top () function. Other operations are similar.
# Include
HDU 1242 rescue
HDU-1242-Rescue
Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1242
Bfs is enough. There may be multiple 'R', and 'A' has only one. From 'A', the first 'r' is the desired one.
It should be noted that there are obstacles in this wide search. If 'X' is encountered, the time is + 2. If a common queue is used, it cannot be ensured that each time the team leaves is the smallest element of time, so we need to use the priority queue. The first time we use t
Rescue
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)Total submission (s): 5895 accepted submission (s): 2192Problem description
Angel
Was caught by the moligpy! He was put in prison by moligpy. The prison
Is described as a n * m (n, m And guards in the prison.
Angel's friends want to save Angel.Their task is: approach angel. We assume that "approach Angel" is to getTo the position where angel stays. When there's a g
there may be no chance to save it.3. If your website disappears because of sudden inaccessibility to the space, such as changing the space, you can find a way to make your homepage more accessible to Baidu, accelerate your re-indexing.4. If it is not because of excessive Seo optimization, do not perform large-scale homepage Content Changes During downgrading. Such as modifying the title, keywords, or modifying the title. We recommend that you improve your links and update the content, and find
[Original] grub rescue appears at startup. Solution: grubrescue
This problem occurs generally because the grub boot file cannot be found due to disk partitioning (which may be caused by GHOST backup. We just need to let it find the boot file.
At this point, the screen prompts grub resume> enter set to see which disk the grub boot is directed.
This indicates that the boot is now directed to the first partition of the first hard disk, and the boot fil
In the recent process of processing data with the shell, it was found that the read command would replace \ t with a space when reading the data, and \ t discard at the end of the line. Look at the help of Read, find-R can retain the escape character, searched for someone also said can use-r, but my experimental results are even if-R is still still. Unfortunately, data processing with awk should be used. Using \ t as the data field delimiter is often used during data mining, and the default key
FDNY to the rescue!
Time limit:1000 ms
Memory limit:10000 K
Total submissions:2368
Accepted:721
DescriptionThe fire department of New York (FDNY) has always been proud of their response time to fires in New York City, but they want to make their response time even better. to help them with their response time, they want to make sure that the dispatchers know the closest firehouse to any address in the city. you ha
Rookie first contact with the MySQL database connection operation, imitate the book wrote the following code, found that can connect to the database, but the SQL statement is always not executed, the SQL statement is not a problem, in the phpMyAdmin can be executed successfully, but here is not, Ask the great God to rescue and see where the problem is.
Reply to discussion (solution)
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.