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 1to 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.

题目大意:从起点走到终点,求最短距离,而且写出最短距离的路径是什么样的:

样例输入:

a8 h1

样例输出:

7 RD RD RD RD RD RD RD

分析:贪心模拟,由题意知道最多有八个可以移动的方向:L,R,U,D,LU,LD,RU,RD,那么当前位置与终点不同就要优先走斜线,模拟一下即可知道最短路径的长度为起点与终点横坐标差的绝对值与纵坐标差的绝对值中较大的那一个。由于走斜线的格式均是L或R+U或D,输出移动动作时可以将走斜线分解为横坐标走一步加纵坐标走一步。

 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
string s1,s2;//记录始末位置坐标 int main(){
char cx,cy;
cin>>s1>>s2;
int x=s1[]-s2[];
int y=s1[]-s2[];
cx=x<?'R':'L';
cy=y<?'U':'D'; if(x<){
x=-x;
}
if(y<){
y=-y;
}
printf("%d\n",x>y?x:y); for( ;x||y; putchar('\n')){
if(x){
x--;
putchar(cx);
}
if(y){
y--;
putchar(cy);
}
} return ;
}

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

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

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

  3. CF3A 【Shortest path of the king】

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

  4. Shortest path of the king

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

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

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

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

  7. 3A. Shortest path of the king

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

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

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

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

随机推荐

  1. Linux目录/usr缩写及目录结构说明

    在 linux 文件结构中,有一个很神奇的目录 —— /usr.   讨论中,大部分观点认为:   usr 是 unix system resources 的缩写: usr 是 user 的缩写: u ...

  2. WIN10系统提示无法使用内置管理员账户打开XXX应用程序怎么办

    重装了系统之后,只保留Administrator账户,结果打开程序的时候回弹出这个提示   运行,输入secpol.msc   本地策略-安全选项,启用下面这个,然后重启计算机      

  3. 尝试新的构造系统 Ninja

    Ninja 是 Chrome 项目的构建工具,用来替换经典工具 make,目前这个开源工具已经被很多其它项目采用.据项目作者描述,创建这个新的构建工具,主要是为了提升大型项目的编译速度. 由于 Nin ...

  4. webpack 配置缓存

    1.输出文件的文件名 加hash 2.提取引导模板 3.模块标识符 https://webpack.docschina.org/guides/caching/#src/components/Sideb ...

  5. M600 Pro 安装问题解决

    1.遥控器版本为1.2.10 提示版本已是最新版本,那么Lightbridge2 必须是1.1.60 不能是1.1.70 2.卸载机翼的时候,尽量用飞机带的那把工具 3.机翼安装 135 逆时针 cc ...

  6. cmd命令行的ping用法

    1.打开cmd 2.ping 域名    (如:ping baidu.com) 3.输出结果 C:\WINDOWS\system32>ping baidu.com 正在 Ping baidu.c ...

  7. Hierarchical softmax(分层softmax)简单描述.

    最近在做分布式模型实现时,使用到了这个函数. 可以说非常体验非常的好. 速度非常快,效果和softmax差不多. 我们知道softmax在求解的时候,它的时间复杂度和我们的词表总量V一样O(V),是性 ...

  8. Effective Java 第三版——75. 在详细信息中包含失败捕获信息

    Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...

  9. Autohotkey window 下宏键盘、宏命令开发入门

  10. SQL Server 2016新特性:Query Store

    使用Query Store监控性能 SQL Server Query Store特性可以让你看到查询计划选择和性能.简化了性能调优,可以快速的发现因为查询计划的选择导致的性能的差别.Query Sto ...