HDU 1813 Escape from Tetris

Source: Internet
Author: User

HDU 1813 Escape from Tetris

 

Escape from TetrisTime Limit: 12000/4000 ms (Java/Other) Memory Limit: 32768/32768 K (Java/Other) Total Submission (s): 1 Accepted Submission (s ): 1 Problem Description Lele was finally beaten by fire because it was facing the Board all night. When he goes to bed every day, he will dream that he will be thrown into a board and cannot find a way out. Then he will wake up from his dream. Over time, Lele has become mentally weak. Whether a dream will become a reality, no one can say, but not afraid of 10 thousand just in case. Now every time Lele sees a chessboard, he will imagine how to escape after being locked in.

Lele's chessboard is square. Some of the grids are bad and cannot go. The rest can go. As long as you walk to the edge of the Board (the outermost circle), you have escaped. Lele dreamed that he would be thrown into a grid that could be taken, but he was not sure which one he was, so he had to be prepared to be thrown into any grid.

Now, Lele can help you to find a shortest sequence for any board. The sequence can include north (up in the MAP) and east (to the right in the map ), south (down in the map), west (left in the map), the four direction commands. No matter which good grid Lele is thrown into, it can walk out of the board in this sequence.
The specific method to escape is: no matter where Lele is thrown, Lele executes commands one by one in the direction of the sequence, and each command follows a grid. If it encounters a bad grid, ignore this command. Of course, if you have escaped, you can ignore the remaining commands in the sequence.

Input this question contains multiple groups of tests, please process until the end of the file. The first line of each group of tests contains a positive integer N (0

 

 

 

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.