Task: TET Tetris Attack Stage II

Task: TET Tetris Attack Stage II

Task: TET Tetris Attack Stage II. Day 2. Source file tet.* 08.02.2007 Available memory: 32 MB. A puzzle called “Tetris Attack” has lately become a very popular game in Byteotia. The game itself is highly sophisticated, so we shall only introduce its simplified rules: the player is givena stack of 2n elements, placed one on another and marked with n different symbols. Exactly two elements of the stack are marked with each symbol. A player’s move consists in swapping two neighbouring elements, ie. interchanging them. If, as a result of the swap, there are some two neighbouring elements marked with the same symbol, they are both removed from the stack. Then all the elements that have been above them fall down in consequence and may very well cause another removals. The player’s goal is emptying the stack in the least possible number of moves. Task Write a programme that: • reads the description of the initial stack content from the standard input, • finds a solution with the minimum number of moves possible, • writes out the outcome to the standard output. Input In the first line of the standard input there is one integer n,1 ≤ n ≤ 50000. The following 2n lines describe the th th initial content of the stack. The (i + 1) line contains one integer ai — the symbol which the i (1 ≤ ai ≤ n) element from the bottom is marked with. Each symbol appears in the stack exactly twice. Moreover, no two identical symbols neighbour initially. The test data is well chosen so that a solution with no more than 1000000 moves exists. Output A solution with the minimum number of moves possible should be written out to the standard output as follows. The first line should contain one integer m — the minimum number of moves. The following m should describe the optimal solution itself, i.e. a sequence of m integers p1,..., pm, one in each line. pi th th th denotes that in i move the player has chosen to swap the pi and (pi + 1) elements from the bottom. If more than one optimal solution exists, your programme should write out any one of them. Example For the input data: v. 1.03 1/2 Tetris Attack 5 2 5 5 2 3 3 4 1 1 p1 =5 4 4 1 2 1 3 5 p2 =2 4 2 2 3 5 5 5 2 the correct result is: 2 5 2 While for the following input data: 3 1 2 3 1 2 3 the correct result is: 3 3 3 2 2 p2 =4 1 3 2 3 p1 =3 3 1 1 4 p3 =2 2 2 2 2 1 1 1 as well as: 3 3 3 2 1 p1 =4 1 2 3 4 p2 =3 3 3 1 3 p3 =2 2 2 2 3 1 1 1 v. 1.03 2/2 Tetris Attack.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us