CF3A.Shortest path of the king

普及-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 tt . As the king is not in habit of wasting his time, he wants to get from his current position ss to square tt 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).

国王独自一人在国际象棋棋盘上。尽管他很孤独,但他并不会灰心,因为他有国家大事要做。例如,他必须对方格 tt 进行访问。因为国王没有浪费时间的习惯,所以他想从目前的位置(方格 ss)上出发,走最少的步数。请你帮他做这件事。

在一次移动中,国王可以到达与他目前所在方格有共同的边或共同的顶点的方格里(通常情况下,他可以移动到 88 个不同的方格里)。

输入格式

The first line contains the chessboard coordinates of square ss , the second line — of square tt .

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.

第一行包含方格 ss 的棋盘坐标,第二行包含方格 tt 的棋盘坐标。

棋盘坐标由两个字符组成,第一个是从 ah 的小写拉丁字母,第二个是从 18 的数字。具体情况如上图所示。

输出格式

In the first line print nn — minimum number of the king's moves. Then in nn 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.

在第一行输出 nn——国王移动的最小步数。然后接下来 nn 行输出移动的每一步。每次移动用 LRUDLULDRURD 中的一个来描述。

LRUD 分别指向左、向右、向上和向下移动,两个字母的组合代表沿着对角线移动(如 RU 代表向右上方移动)。如果答案不唯一,请输出任意一个答案。

输入输出样例

  • 输入#1

    a8
    h1

    输出#1

    7
    RD
    RD
    RD
    RD
    RD
    RD
    RD
首页