#C. Shortest path of the king

    远端评测题 1000ms 64MiB

Shortest path of the king

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

题目描述

国王独自留在棋盘上。尽管孤独,他并没有丧失信心,因为他有国家重要的事务。例如,他必须对 t 方格进行正式访问。由于国王不习惯浪费时间,他希望从当前位置 st 方格的最少移动次数。帮助他做到这一点。

每一步,国王可以移动到与当前所在方格有公共边或公共顶点的方格(通常有8个不同的方格可以移动)。

第一行包含方格 s 的棋盘坐标,第二行包含方格 t 的棋盘坐标。

棋盘坐标由两个字符组成,第一个是小写拉丁字母(从 ah),第二个是从 18 的数字。

在第一行打印 n — 国王的最少移动次数。然后在 n 行中打印移动本身。每个移动都用8个中的一个描述:L, R, U, D, LU, LD, RU 或者RD.

L, R, U, D 分别代表向左、向右、向上和向下移动(根据图片),2个字母的组合代表对角线移动。如果答案不唯一,打印其中任意一个。

输入

第一行包含方格 s 的棋盘坐标,第二行包含方格 t 的棋盘坐标。

棋盘坐标由两个字符组成,第一个是小写拉丁字母(从 ah),第二个数字是从18.

输出

在第一行打印 n — 国王的最少移动次数。然后在 n 行中打印移动本身。每个移动都用8个中的一个描述:L, R, U, D, LU, LD, RU 或者RD.

L, R, U, D 分别代表向左、向右、向上和向下移动(根据图片),2个字母的组合代表对角线移动。如果答案不唯一,打印其中任意一个。

样例

a8
h1
7
RD
RD
RD
RD
RD
RD
RD

Description

The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this.

In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).

The first line contains the chessboard coordinates of square s, the second line — of square t.

Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.

In the first line print n — minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.

L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.

Input

The first line contains the chessboard coordinates of square s, the second line — of square t.

Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.

Output

In the first line print n — minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.

L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.

7.17下午1点半作业

未认领
状态
已结束
题目
3
开始时间
2023-7-17 0:00
截止时间
2023-7-25 23:59
可延期
24 小时