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).

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.

Examples
Input

Copy
a8
h1
Output

Copy
7
RD
RD
RD
RD
RD
RD
RD
题目大意:在棋盘上要从a(a8)到(h1)。输出最小的步数和路线(其中L:向左,R:向右,U:向上,D:向下)
解题思路:这题其实很简单.....横向长度和纵向长度都是确定的,主要刚开始看这道题的时候,看到国王可以斜着走于是想复杂,其实不管
国王是左上方斜走,右上斜走,左下斜走,右下斜走,有两点是唯一不变的,
(1)斜着走必定会在x方向改变1,y方向改变1。
(2)四个斜着走的方向在每次测试用例中只会出现一种。
(就是比如终点在右下方,国王在斜着走的步骤就只会选择右下了,如果不是唯一,则肯定不是最短路径!)
然后下面的代码就很容易理解了.
AC代码1:比较简单易懂
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
inline int read() {int x=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
typedef long long ll;
const int maxn = 1e5+;
char a[],b[];
int main()
{
scanf("%s%s",a,b);
char c,d;
int x=a[]-b[],y=a[]-b[];
if(x>){
c='L';
}
else{
x=-x;
c='R';
}
if(y>){
d='D';
}
else{
y=-y;
d='U';
}
printf("%d",x>y?x:y);
while(x||y){
printf("\n");
if(x){
x--;
printf("%c",c);
}
if(y){
y--;
printf("%c",d);
}
}
return ;
}

   AC代码2:

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
inline int read() {int x=,f=;char c=getchar();while(c!='-'&&(c<''||c>''))c=getchar();if(c=='-')f=-,c=getchar();while(c>=''&&c<='')x=x*+c-'',c=getchar();return f*x;}
typedef long long ll;
const int maxn = 1e5+;
char a[],b[];
int main()
{
char c,d;
scanf("%s%s",a,b);
int x=a[]-b[],y=a[]-b[];
c=((x<)?x=-x,'R':'L');
d=((y<)?y=-y,'U':'D');
printf("%d",x>y?x:y);
while(x||y){
printf("\n");
if(x){
x--;
printf("%c",c);
}
if(y){
y--;
printf("%c",d);
}
}
return ;
}

codeforces- Shortest path of the king的更多相关文章

  1. Codeforces Beta Round #3 A. Shortest path of the king 水题

    A. Shortest path of the king 题目连接: http://www.codeforces.com/contest/3/problem/A Description The kin ...

  2. Codeforces-A. Shortest path of the king(简单bfs记录路径)

    A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...

  3. Codeforces 3A-Shortest path of the king(BFS打印路径)

    A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...

  4. node搜索codeforces 3A - Shortest path of the king

    发一下牢骚和主题无关: 搜索,最短路都可以     每日一道理 人生是洁白的画纸,我们每个人就是手握各色笔的画师:人生也是一条看不到尽头的长路,我们每个人则是人生道路的远足者:人生还像是一块神奇的土地 ...

  5. Codeforces Beta Round #3 A. Shortest path of the king

    标题效果: 鉴于国际棋盘两点,寻求同意的操作,是什么操作的最小数量,在操作过程中输出. 解题思路: 水题一个,见代码. 以下是代码: #include <set> #include < ...

  6. A - Shortest path of the king (棋盘)

    The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...

  7. Shortest path of the king

    必须要抄袭一下这个代码 The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose h ...

  8. CF3A Shortest path of the king

    The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...

  9. 3A. Shortest path of the king

    给你一个的棋盘, 问:从一个坐标到达另一个坐标需要多少步? 每次移动可以是八个方向.   #include <iostream> #include <cmath> #inclu ...

  10. CF3A 【Shortest path of the king】

    一句话题意:在8 * 8的棋盘上,输出用最少步数从起点走到终点的方案 数据很小,可以广搜无脑解决 定义数据结构体 struct pos{ int x,y,s; //x.y表示横纵坐标,s表示步数 ]; ...

随机推荐

  1. Blocked Billboard II

    前言 今天比赛真的状态不好(腐了一小会),导致差点爆0. 这个题解真的是在非常非常专注下写出来的,要不然真的心态崩. 刚换了域名,发现了美化脚本的bug,有点担心(汗-_-||). 题目 题目描述 奶 ...

  2. Oracle 11G统计信息自动收集及调整

    查询统计信息的收集所对应的task,以及当前状态 col CLIENT_NAME for a50col TASK_NAME for a20SELECT client_name, task_name, ...

  3. idea中的springboot+gradle项目报错springboot configuration annotation processor not found in classpath

    idea中的springboot项目,打开某个类run.halo.app.config.properties.HaloProperties.java,报错(使用gradle编译): springboo ...

  4. python浅析模块,包及其相关用法

    一,模块 什么是模块? 在计算机程序的开发过程中,随着程序代码越写越多,在一个文件里面,代码会越来越长,越来越不容易维护. 为了编写可以维护的代码,我们把很多函数分组,分别放到不同额文件,这样,每个文 ...

  5. ajax请求无法下载文件的原因

    原因: Ajax下载文件的这种方式本来就是禁止的.出于安全因素的考虑,javascript是不能够保存文件到本地的, 所以ajax考虑到了这点,只是接受json,text,html,xml格式的返回值 ...

  6. LoadRunner通过webservice协议调用WSDL接口时,返回值不正确

    有可能是某些传参空的值导致的. 解决办法:注释掉空值传参.或者将其值转变为true ”ProductIDSpecified=true“,

  7. 关于php/js抓取/采集

    前段时间用php的一个插件(phpQuery+queryList)写了采集某个博客的一些博文,然后用linux的自动运行跑,感觉还不错. 但在很久之前就已经听说了另外一个插件,可以很好的进行采集,叫做 ...

  8. thinkphp 连接webservice接口

    嗯,我现在真的好像骂人啊,但是我又是个文明的人,所以我就写出来让自己冷静一下 ok,正事,thinkphp连别人写的webservice接口 刚开始他叫什么nc接口,就把我给骗了,这就是人家的名字,和 ...

  9. redis 字符串操作

    redis 字符串创建SET操作 127.0.0.1:6379> set number "10086" OK 127.0.0.1:6379> set book &quo ...

  10. 安装搭建appium运行环境

    整体步骤: 1.安装appium依赖的Python包(Appium-Python-Client): 2.安装Appium Desktop(集成了appium server和node.js,所以不需要额 ...