QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100

#6246. 螺旋正方形

Statistics

D:螺旋方阵

Kian 被困在一个房间里,什么也看不见。我们知道这个房间的地面是一个 $n \times n$ 的正方形,铺满了正方形瓷砖。每块瓷砖都有一个唯一的编号,且编号呈螺旋状排列。例如,下图展示了 $n = 5$ 时瓷砖的编号方式。

Kian 知道房间里有一支蜡烛,他想找到它,但因为房间很暗,他什么也看不见。他请求你根据他当前所在的瓷砖编号和蜡烛所在的瓷砖编号,指导他需要在每个方向上移动多少距离才能到达蜡烛所在的位置。

输入格式

输入仅一行,包含三个用空格分隔的整数 $n$、$s$ 和 $d$,分别代表房间的边长、Kian 所在的瓷砖编号以及蜡烛所在的瓷砖编号。

输出格式

第一行输出一个数字和一个字符,中间用空格分隔。数字表示 Kian 在水平方向上需要移动的距离,如果需要向左移动,字符为 L;如果需要向右移动,字符为 R。如果 Kian 不需要进行水平移动,则忽略此行。

第二行输出一个数字和一个字符,中间用空格分隔。数字表示 Kian 在垂直方向上需要移动的距离,如果需要向上移动,字符为 U;如果需要向下移动,字符为 D。如果 Kian 不需要进行垂直移动,则忽略此行。

数据范围

  • $1 \le n \le 2000$
  • $1 \le s \neq d \le n^2$

样例

样例输入 1

5 1 25

样例输出 1

2 R
2 U

样例输入 2

5 3 22

样例输出 2

3 U

样例输入 3

15 67 24

样例输出 3

3 R
8 U

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.