当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2598:Manipulating the Power Square

题目描述
Rosalina finds Super Mario puzzling over the Power Square and gives him another hint on how to unlock its power. ”Keep swapping 0 with one of its neighbors! I’ll tell you which neighbor,” Rosalina says to Mario. Rosalina then gives Mario a sequence of directions on which neighbor to swap with 0.
输入解释
Input is a description of of the Power Square, followed by a number of commands. The first line is the size of the Power Square n. You may assume n<=100. The second line contains the n2 values in the Power Square, separated by spaces. Values start from the top left corner and move from left to right, moving down one row to the leftmost position when a row is filled.
Following the Power Square description are a number of commands, with each command on a separate line. Each command begins with the name of the command, followed by any additional command parameters.
There will no more than 100 commands.
输出解释
The command ”SHOW” causes the current state of the Power Square to be displayed in n × n
form (each row of n values on a single line, separated by spaces), followed by a blank line.
The command ”MOVE” is followed by one more more moves: ”up”, ”down”, ”left”, or ”right”.
Each move is executed as follows:
– For ”up”, swap 0 with its neighbor above.
– For ”left”, swap 0 with its left neighbor.
– For ”right”, swap 0 with its right neighbor.
– For ”down”, swap 0 with its neighbor below.
If move attempts to swap 0 with a non-existent neighbor, then output ”FAILED” on a single line and stop attempting the remaining moves. If the move succeeds, ”MOVED” is output on a single line. In either case, the state of the Power Square is changed to reflect the moves made.
输入样例
3
8 7 6 5 4 3 2 1 0
SHOW
MOVE up
SHOW
3
8 7 6 5 4 3 2 1 0
SHOW
MOVE up right
输出样例
8 7 6
5 4 3
2 1 0

MOVED
8 7 6
5 4 0
2 1 3

8 7 6
5 4 3
2 1 0

FAILED
来自杭电HDUOJ的附加信息
Recommend lcy

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-2598

最后修改于 2020-10-25T22:55:02+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 32768/32768K(Java/Others)