A9219 | Neatness
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Simon loves neatness. So before he goes to bed, Simon wants to complete all chores in the house.
Simon's house looks like a rectangular table consisting of $n$ rows and $n$ columns from above. All rows of the table are numbered from $1$ to $n$ from top to bottom. All columns of the table are numbered from $1$ to $n$ from left to right. Each cell of the table is a room. Pair $(x,y)$ denotes the room, located at the intersection of the $x$ -th row and the $y$ -th column. For each room we know if the light is on or not there.
Initially Simon is in room $(x_{0},y_{0})$ . He wants to turn off the lights in all the rooms in the house, and then return to room $(x_{0},y_{0})$ . Suppose that at the current moment Simon is in the room $(x,y)$ . To reach the desired result, he can perform the following steps:
1. The format of the action is "1". The action is to turn on the light in room $(x,y)$ . Simon cannot do it if the room already has light on.
2. The format of the action is "2". The action is to turn off the light in room $(x,y)$ . Simon cannot do it if the room already has light off.
3. The format of the action is "dir" ( $dir$ is a character). The action is to move to a side-adjacent room in direction $dir$ . The direction can be left, right, up or down (the corresponding dir is L, R, U or D). Additionally, Simon can move only if he see a light in the direction $dir$ . More formally, if we represent the room, Simon wants to go, as $(nx,ny)$ , there shold be an integer $k$ $(k>0)$ , that room $(x+(nx-x)k,y+(ny-y)k)$ has a light. Of course, Simon cannot move out of his house.
Help Simon, find the sequence of actions that lets him achieve the desired result.
Simon's house looks like a rectangular table consisting of $n$ rows and $n$ columns from above. All rows of the table are numbered from $1$ to $n$ from top to bottom. All columns of the table are numbered from $1$ to $n$ from left to right. Each cell of the table is a room. Pair $(x,y)$ denotes the room, located at the intersection of the $x$ -th row and the $y$ -th column. For each room we know if the light is on or not there.
Initially Simon is in room $(x_{0},y_{0})$ . He wants to turn off the lights in all the rooms in the house, and then return to room $(x_{0},y_{0})$ . Suppose that at the current moment Simon is in the room $(x,y)$ . To reach the desired result, he can perform the following steps:
1. The format of the action is "1". The action is to turn on the light in room $(x,y)$ . Simon cannot do it if the room already has light on.
2. The format of the action is "2". The action is to turn off the light in room $(x,y)$ . Simon cannot do it if the room already has light off.
3. The format of the action is "dir" ( $dir$ is a character). The action is to move to a side-adjacent room in direction $dir$ . The direction can be left, right, up or down (the corresponding dir is L, R, U or D). Additionally, Simon can move only if he see a light in the direction $dir$ . More formally, if we represent the room, Simon wants to go, as $(nx,ny)$ , there shold be an integer $k$ $(k>0)$ , that room $(x+(nx-x)k,y+(ny-y)k)$ has a light. Of course, Simon cannot move out of his house.
Help Simon, find the sequence of actions that lets him achieve the desired result.
输入格式
The first line contains three positive integers $n,x_{0},y_{0}$ $(2<=n<=500,1<=x_{0},y_{0}<=n)$ .
Next $n$ lines contain the description of rooms in the house. The $i$ -th line contains $n$ space-separated integers $a_{i1},a_{i2},...,a_{in}$ . If number $a_{ij}$ equals zero, then room $(i,j)$ has light off, and if number $a_{ij}$ equals one, then room $(i,j)$ has light on. It is guaranteed that at least one room has light on.
Next $n$ lines contain the description of rooms in the house. The $i$ -th line contains $n$ space-separated integers $a_{i1},a_{i2},...,a_{in}$ . If number $a_{ij}$ equals zero, then room $(i,j)$ has light off, and if number $a_{ij}$ equals one, then room $(i,j)$ has light on. It is guaranteed that at least one room has light on.
输出格式
If there is no desired sequence of actions, print "NO" (without the quotes). Otherwise, print "YES" (without the quotes) and the description of the required sequence of actions as a string. Note that you do not have to minimize the length of the sequence of actions but you shouldn't use more than $3·10^{6}$ actions.
输入输出样例
输入 #1
3 1 1 1 0 0 0 1 0 1 0 0
输出 #1
YES D1R2L2D2UU2
输入 #2
3 1 1 1 0 0 0 1 0 0 0 1
输出 #2
NO
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted