#P7742. [COCI 2011/2012 #3] DIGITALNA
[COCI 2011/2012 #3] DIGITALNA
Description
Not long ago, Mirko’s grandparents had to switch from an analog TV receiver to a digital TV receiver. On their old analog receiver, they could only watch two channels—BLJTV1 and BLJTV2. After switching to the digital receiver, they got dozens of new channels, but they still want to watch only the same two old channels. They asked Mirko to adjust the channel menu so that BLJTV1 is on the first channel and BLJTV2 is on the second channel.
After being turned on, the digital receiver creates a list of available channels. All channels are different, and the list always contains BLJTV1 and BLJTV2. After Mirko found the remote control, he started adjusting the menu. The menu contains the channel list and an arrow that marks the currently selected channel. When entering the menu, the arrow points to the first channel in the list.
There are four operations in the menu. In the operation sequence, each operation is represented by the number in front of it:
- Move the arrow down by one position (from channel to channel ).
- Move the arrow up by one position (from channel to channel ).
- Move the arrow and the selected channel down by one position (channels and swap positions, and the arrow ends at the position of channel ).
- Move the arrow and the selected channel up by one position (channels and swap positions, and the arrow ends at the position of channel ).
The menu is stable, so invalid commands (for example, commands that would move the arrow outside the channel list) are ignored.
Write a program that, given a channel list, outputs any sequence of operations such that after executing it, BLJTV1 is in the first position of the channel list and BLJTV2 is in the second position. In addition, the length of the sequence should be less than . The order of all other channels is arbitrary.
Input Format
The input has lines.
The first line contains an integer , the number of channels.
The next lines each contain a string , the name of a channel.
The input guarantees that the channel list contains both BLJTV1 and BLJTV2, and that there exists at least one feasible operation sequence.
Output Format
Output only one line: a string representing an operation sequence that can achieve the requirement.
3
ABC
BLJTV1
BLJTV2
33
4
ABC1
ABC02
BLJTV2
BLJTV1
11144411144
4
ABC1
ABC02
BLJTV2
BLJTV1
33144413
Hint
Constraints
For all testdata, , each channel name has length at most , and consists only of uppercase English letters and digits.
Source
This problem is from COCI 2011-2012 CONTEST 3 T1 DIGITALNA. Using the original testdata configuration, the full score is points.
Translated and organized by Eason_AC.
Thanks to yzy1 for providing the SPJ for this problem.
Translated by ChatGPT 5
京公网安备 11011102002149号