A15954 | Toy Machine
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There is a toy machine with toys arranged in two rows of $n$ cells each ( $n$ is odd).
 Initial state for $n=9$ .Initially, $n-2$ toys are placed in the non-corner cells of the top row. The bottom row is initially empty, and its leftmost, rightmost, and central cells are blocked. There are $4$ buttons to control the toy machine: left, right, up, and down marked by the letters L, R, U, and D correspondingly.
When pressing L, R, U, or D, all the toys will be moved simultaneously in the corresponding direction and will only stop if they push into another toy, the wall or a blocked cell. Your goal is to move the $k$ -th toy into the leftmost cell of the top row. The toys are numbered from $1$ to $n-2$ from left to right. Given $n$ and $k$ , find a solution that uses at most $1\,000\,000$ button presses.
To test out the toy machine, a [web page](https://assets.codeforces.com/files/56ff21637146a30d/game.html) is available that lets you play the game in real time.
 Initial state for $n=9$ .Initially, $n-2$ toys are placed in the non-corner cells of the top row. The bottom row is initially empty, and its leftmost, rightmost, and central cells are blocked. There are $4$ buttons to control the toy machine: left, right, up, and down marked by the letters L, R, U, and D correspondingly.
When pressing L, R, U, or D, all the toys will be moved simultaneously in the corresponding direction and will only stop if they push into another toy, the wall or a blocked cell. Your goal is to move the $k$ -th toy into the leftmost cell of the top row. The toys are numbered from $1$ to $n-2$ from left to right. Given $n$ and $k$ , find a solution that uses at most $1\,000\,000$ button presses.
To test out the toy machine, a [web page](https://assets.codeforces.com/files/56ff21637146a30d/game.html) is available that lets you play the game in real time.
输入格式
The first and only line contains two integers, $n$ and $k$ ( $5 \le n \le 100\,000$ , $n$ is odd, $1 \le k \le n-2$ ) — the number of cells in a row, and the index of the toy that has to be moved to the leftmost cell of the top row.
输出格式
On a single line, output a description of the button presses as a string of at most $1\,000\,000$ characters. The string should only contain the characters L, R, U, and D. The $i$ -th character in the string is the $i$ -th button that is pressed. After all the button presses are performed, the $k$ -th toy should be in the leftmost cell of the top row.
If there are multiple solutions, print any. The number of button presses does not have to be minimized.
If there are multiple solutions, print any. The number of button presses does not have to be minimized.
输入输出样例
输入 #1
5 1
输出 #1
RDL
输入 #2
7 2
输出 #2
RDL
In the first example, there will be $5-2 = 3$ toys. The first toy needs to end up in the leftmost cell of the top row. The moves RDL will achieve this, see the picture for a better understanding. Another possible solution would be to do one button press L.
 Visualization of the moves for the first example.
 Visualization of the moves for the first example.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted