#P10493. Bloxorz II
Bloxorz II
Problem Description
Because of a great catastrophe, the Academy of Sciences has had no new students for many years (in this world, the Academy of Sciences also serves as a university). Therefore, this year's entrance test has milestone-like significance. As the top information expert of the Academy, this task naturally falls on you. After some thought, you decide to make a problem based on the Bloxorz game.
In the Bloxorz game, as shown in the figure below, there is a hole as the target on a platform, and a rectangular block. The block can roll along its edges on the platform, but it must not lose contact with the platform.

The following figure shows the situation after the block in the above figure rolls to the right.

The next figure shows the situation after it rolls forward.

The task is to get the block into the target hole. Of course, at that time the block should be standing upright.
One roll is called one step. Your problem is: for a given situation, compute the minimum number of steps needed to roll the block into the target hole. Naturally, for freshmen, this is a very hard problem.
The freshmen you defeated feel unconvinced. So they come up with an even harder problem for you to solve:
There is an infinite platform with a coordinate system on it. Now the target hole is at . The position and state of the block (standing upright, parallel to the -axis, or parallel to the -axis) are given. Compute the minimum number of steps needed to make the block fall into the hole.
As a top information expert... of course this is not hard for you.
Input Format
The input file contains multiple sets of testdata.
Each test case is on one line in the format C x y, where C is a letter and and are two integers. This means the block covers the cell on the platform, and its state is C.
If C is the letter U, it means the block is standing upright.
If C is the letter V, it means the block is parallel to the -axis, and the other covered cell is .
If C is the letter H, it means the block is parallel to the -axis, and the other covered cell is .
The input ends at EOF.
Output Format
For each test case, output the answer on a separate line.
U 0 0
H 0 0
V 1 0
0
4
1
Hint
For of the testdata, .
For of the testdata, , and there are no more than test cases in the input.
Translated by ChatGPT 5