#P9626. [ICPC2020 Nanjing R] Evil Coordinate
[ICPC2020 Nanjing R] Evil Coordinate
题目描述
A robot is standing on an infinite 2-dimensional plane. Programmed with a string of length , where $s_i \in \{\text{`U'}, \text{`D'}, \text{`L'}, \text{`R'}\}$, the robot will start moving from and will follow the instructions represented by the characters in the string.
More formally, let be the current coordinate of the robot. Starting from , the robot repeats the following procedure times. During the -th time:
- If the robot moves from to ;
- If the robot moves from to ;
- If the robot moves from to ;
- If the robot moves from to .-
However, there is a mine buried under the coordinate . If the robot steps onto during its movement, it will be blown up into pieces. Poor robot!
Your task is to rearrange the characters in the string in any order, so that the robot will not step onto .
输入格式
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains two integers and () indicating the coordinate of the mine.
The second line contains a string of length (, $s_i \in \{\text{`U'}, \text{`D'}, \text{`L'}, \text{`R'}\}$) indicating the string programmed into the robot.
It's guaranteed that the sum of of all test cases will not exceed .
输出格式
For each test case output one line. If a valid answer exists print the rearranged string, otherwise print Impossible
instead. If there are multiple valid answers you can print any of them.
题目大意
一个机器人位于平面直角坐标系的原点处。给定一串指令,由 UDLR
四个字符构成,分别表示向上下左右移动 单位长度。
处埋有地雷,你需要任意重排指令使得机器人不会经过该坐标,判定是否有解并构造方案。
多组数据。指令长度不超过 ,长度总和不超过 。
5
1 1
RURULLD
0 5
UUU
0 3
UUU
0 2
UUU
0 0
UUU
LDLRUUR
UUU
Impossible
Impossible
Impossible