4191: 弗拉迪克和最喜欢的游戏

内存限制:256 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:10 通过:2

题目描述


这是一个交互式问题。
弗拉迪克有最喜欢的游戏,他所有的空闲时间都在玩。
游戏字段可以表示为 n×m 矩阵,该矩阵由三种类型的单元格组成:
«..“ - 普通单元格,玩家可以访问它。
«F» − 完成单元格,玩家必须完成他的方式才能获胜。这种类型的单元格只有一个。
«*» - 危险的牢房,如果玩家来到这个牢房,他就输了。
最初播放器位于坐标为 (1,1) 的左上角单元格中。
玩家可以使用4个按钮“U”,“D”,“L”,“R”,每个按钮分别向上,向下,向左和向右移动玩家。
但这并不容易!有时朋友玩游戏并更改按钮的功能。按钮“L”和“R”的功能可以交换,按钮“U”和“D”的功能也可以交换。请注意,按钮的功能只能在游戏开始时更改。
帮助弗拉迪克赢得比赛!

This is an interactive problem.
Vladik has favorite game, in which he plays all his free time.
Game field could be represented as n×m matrix which consists of cells of three types:
  • «.» − normal cell, player can visit it.
  • «F» − finish cell, player has to finish his way there to win. There is exactly one cell of this type.
  • «*» − dangerous cell, if player comes to this cell, he loses.
Initially player is located in the left top cell with coordinates (1,1).
Player has access to 4 buttons "U", "D", "L", "R", each of them move player up, down, left and right directions respectively.
But it’s not that easy! Sometimes friends play game and change functions of buttons. Function of buttons "L" and "R" could have been swapped, also functions of buttons "U" and "D" could have been swapped. Note that functions of buttons can be changed only at the beginning of the game.
Help Vladik win the game!
Input
First line contains two space-separated integers n and m (1≤n,m≤100) − number of rows and columns respectively.
Each of next n lines contains m characters describing corresponding row of field. Set of characters in field is described above.
Guaranteed that cell with coordinates (1,1) is normal and there is at least one way from initial cell to finish cell without dangerous cells.
Interaction
You can press buttons no more than n·m times.
To press a button you should print "U", "D", "L", "R" in new line. It’s necessary to print newline character and flush output. After flushing buffer you should read answer from input data. Answer is the pair of space-separated integers x, y − new position of player. In case, if there is no cell in direction of moving, position will not change. If after any move player lost, in other words player move to dangerous cell, then x and y will be equal to -1.
If after any move player is in finish or dangerous cell, then you should terminate your program.
To finish output buffer (i. e. for operation flush) right after printing direction and newline you should do next:
  • fflush(stdout) in C++
  • System.out.flush() in Java
  • stdout.flush() in Python
  • flush(output) in Pascal
  • read documentation for other languages.
Hacks
To perform a hack you should use this format:
n m swapLR swapUD 
a_1 
a_2 
... 
a_n
Where n, m− number of rows and columns in game field. swapLR is equal to 1 in case, when directions "L’’ and "R’’ is swapped, and equal to 0 otherwise. swapUD is equal to 1, when directions "U’’ and "D’’ is swapped, and equal to 0 otherwise. a1,a2,...,an − description of corresponding rows of game field.
Example
Input
4 3
...
**.
F*.
...
1 1
1 2
1 3
1 3
2 3
3 3
4 3
4 2
4 1
3 1
Output
R
L
L
D
U
U
U
R
R
D
Note
In first test case all four directions swapped with their opposite directions. Protocol of interaction In more convenient form:

This test could be presenter for hack in following way:
4 3 1 1
...
**.
F*.
...

输入格式

输入
第一行包含两个空格分隔的整数 n 和 m (1≤n,m≤100) − 分别是行数和列数。
接下来的 n 行中的每一行都包含描述相应字段行的 m 个字符。字段中的字符集如上所述。
保证坐标为 (1,1) 的单元格是正常的,并且从初始单元格到没有危险单元格的完成单元格至少有一种方法。

输出格式

您可以按下按钮不超过 2·n·m 次。
要按下按钮,您应该在新行中打印“U”,“D”,“L”,“R”。有必要打印换行符和刷新输出。刷新缓冲区后,您应该从输入数据中读取答案。答案是一对空格分隔的整数 x, y − 玩家的新位置。如果移动方向上没有单元格,则位置不会改变。如果玩家在任何移动后输了,换句话说,玩家移动到危险单元格,则 x 和 y 将等于 -1。
如果在任何移动后玩家处于完成或危险单元,那么您应该终止您的程序。
要在打印方向和换行符后立即完成输出缓冲区(即用于操作刷新),您应该执行以下操作:
fflush(stdout) in C++
System.out.flush() in Java
stdout.flush() in Python
帕斯卡中的冲洗(输出)
阅读其他语言的文档。
黑客
要执行黑客攻击,您应该使用以下格式:

n m swapLR swapUD
a_1
a_2
...
a_n
其中 n、m− 游戏字段中的行数和列数。当方向“L”和“R”被交换时,swapLR 等于 1,否则等于 0。当方向“U”和“D”被交换时,swapUD 等于 1,否则等于 0。A1,A2,..., − 游戏字段相应行的描述。

输入
4 3
...
**.
F*.
...
1 1
1 2
1 3
1 3
6 ·
3 3
4 3
4 2
4 1
3 1
输出
R
L
L
D
U
U
U
R
R
D
注意
在第一个测试用例中,所有四个方向都与相反的方向交换。交互协议 以更方便的形式:

此测试可以通过以下方式成为黑客的演示者:

4 3 1 1
...
**.
F*.
...

输入样例 复制

4 3
...
**.
F*.
...
1 1
1 2
1 3
1 3
2 3
3 3
4 3
4 2
4 1
3 1

输出样例 复制

R
L
L
D
U
U
U
R
R
D