Hdu 1072 maid

Source: Internet
Author: User

Hdu 1072 maid

Obtain the time for Ignatius to exit the maze.

Note: 0 indicates the wall, 1 indicates the blank, 2 indicates the starting point, 3 indicates the target point, 4 indicates the bomb time reset device, (1 <= n, m <= 8 ).

Idea: if this question is not 4, it is a simple deep search. You only need to leave the time device again.

 

 

/* Idea: */# include
 
  
# Include
  
   
Using namespace std; struct node {int x; int y; int time; // record time int step; // record step} hero; /* n indicates that the Row m indicates that the column map length is 9, a maximum of 8 Data dir indicates the upper and lower left, the first represents (x-1, y + 0 ), x is the time remaining when the control line mark records the first time the hero has walked through this point */int n, m; int dir [] [2] = }, {}, {0,-1}, {}; int map [9] [9]; int main () {int t; cin> t; void myInput (); void breadthFirstSearch (); while (t --) {cin> n> m; myInput (); breadthFirstSearch ();} return 0 ;} void myInput () {for (int I = 0; I
   
    
> Map [I] [j]; // find a hero and record his information. if (map [I] [j] = 2) {// The integer data in the struct can be directly assigned a value, and the string cannot be hero. x = I; hero. y = j; hero. time = 6; hero. step = 0 ;}}} void breadthFirstSearch () {queue
    
     
Que; // The first step is to press hero into the stack. que. push (hero);/* heroBunshin-separation of heroes, you know, let the separation test, only the body will go the right way */node heroBunshin, newNode; while (! Que. empty () {// The first element in step 2 pops up the stack heroBunshin = que. front (); que. pop ();/* search for actions on all sides */for (int I = 0; I <4; I ++) {// copy newNode = heroBunshin first; newNode. x = newNode. x + dir [I] [0]; newNode. y = newNode. y + dir [I] [1]; newNode. step ++; newNode. time --; // determine the boundary if (newNode. x> = 0 & newNode. y> = 0 & newNode. x
     
      
0) {// walk out of the maze, map = 3 to end the program or all the elements in the stack exit the stack if (map [newNode. x] [newNode. y] = 3) {cout <
      
       

 

 

 

 

Nightmare Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission (s): 8533 Accepted Submission (s): 4088Problem DescriptionIgnatius had a nightmare last night. He found himself in a labyrinth with a time bomb on him. Ignatius had a nightmare last night. He found himself with a bomb and was in the maze. The labyrinth has an exit, Ignatius shocould get out of the labyrinth before the bomb explodes. The Maze has an exit. Ignatius should leave the maze before the bomb explosion. The initial exploding time of the bomb is set to 6 minutes. The initial explosion time of the time bomb is 6 seconds. To prevent the bomb from exploding by shake, Ignatius had to move slowly, Ignatius must be careful in action To prevent bombs from exploding during the movement, that is to move from one area to the nearest area (that is, if Ignatius stands on (x, y) now, if Ignatius is in the (x, y) Coordinate, when he wants to move to a nearby location, he cocould only on (x + 1, y), (x-1, y), (x, y + 1), or (x, Y-1) in the next minute) takes him 1 minute. he can only move to (x + 1, y), (x-1, y), (x, y + 1), or (x, Y-1) one point per second. Some areas in the labyrinth contains a Bomb-Reset-Equipment. Some places in the Maze contain bombs. They cocould reset the exploding time to 6 minutes. Their bomb time is 6 seconds. Given the layout of the labyrinth and Ignatius 'start position, which gives the layout of the maze and the starting point of Ignatius. please tell Ignatius whether he cocould get out of the labyrinth, please write a program to tell Ignatius whether he can walk out of the maze. if he cocould, output the minimum time that he has to use to find the exit of the labyrinth, else output-1. if he can, please output his time out of the maze; otherwise, output-1; Here are some rules: the game rules are as follows: 1. we can assume the labyrinth is a 2 array. we can think of the maze as a 2-dimensional array. 2. each minute, Ignatius cocould only get to one of the nearest area, and he shocould not walk out of the border, of course he cocould not walk on a wall, too. ignatius can only move one step every second, and it is near. He cannot walk out of the boundary, and of course he cannot walk on the wall. 3. if Ignatius get to the exit when the exploding time turns to 0, he can't get out of the labyrinth. before the bomb explosion, if Ignatius did not walk out of the maze, Ignatius would not be able to walk out of the maze. 4. if Ignatius get to the area which contains Bomb-Rest-Equipment when the exploding time turns to 0, he can't use the equipment to reset the bomb. when the bomb is 0, if Ignatius goes to a place where there is a reset bomb, then he cannot reset the Time of the bomb explosion. It can be said that he is dead. 5. A Bomb-Reset-Equipment can be used as frequently times as you wish, if it is needed, Ignatius can get to any areas in the labyrinth as frequently times as you wish. ignatius can adjust the time if any bomb reset device is used. 6. the time to reset the exploding time can be ignore, in other words, in other words, you can ignore The time reset explosion time, if Ignatius get to an area which contain Bomb-Rest-Equipment, and the exploding time is larger than 0, the exploding time wocould be reset to 6. if Ignatius goes to a bomb reset area and the bomb time is greater than 0, the explosion time will be reset to 6. InputThe input contains several test cases. The input statement contains multiple groups of test events. The first line of the input is a single integer T which is the number of test cases. The first line of the input has an integer T, which indicates the number of test events. T test cases follow. Then enter T test data. Each test case starts with two integers N and M (1 <= N, Mm = 8) which indicate the size of the labyrinth. the start line of each test event contains two integers N and M (1 <= n, m <= 8), indicating the size of the maze. Then N lines follow, each line contains M integers. Then input N rows of data, each row has M integers. The array indicates the layout of the labyrinth. The array represents the layout of the maze. There are five integers which indicate the different type of area in the labyrinth: There are five types of data in The maze, which are shown as follows: 0: the area is a wall, ignatius shocould not walk on it.0 indicates the wall, And Ignatius cannot move on it. 1: The area contains nothing, Ignatius can walk on it.1 indicates that there is nothing, And Ignatius can be moved at will. 2: Ignatius 'start position, Ignatius starts his escape from this position.2 indicates the starting position of Ignatius and the escape starting point of Ignatius. 3: The exit of the labyrinth, Ignatius 'target position.3 indicates The exit of the maze and The Ignatius target location. 4: The area contains a Bomb-Reset-Equipment, Ignatius can delay the exploding time by walking to these areas.4 indicates a time Bomb Reset, when Ignatius is on the top, you can reset the explosion time. OutputFor each test case, if Ignatius can get out of the labyrinth, you shocould output the minimum time he needs, else you shoshould just output-1. for each test event, if Ignatius can exit the maze, you should output the time for him to exit the maze; otherwise, output-1; Sample Input
33 32 1 11 1 01 1 34 82 1 1 0 1 1 1 01 0 4 1 1 0 4 11 0 0 0 0 0 0 11 1 1 4 1 1 1 35 81 2 1 1 1 1 1 4 1 0 0 0 1 0 0 1 1 4 1 0 1 1 0 1 1 0 0 0 0 3 0 1 1 1 4 1 1 1 1 1 

Sample Output
4-113

Author Ignatius. L

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.