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. wpf 控件添加背景图片

    方法一,xaml中: <控件> <控件.Background> <ImageBrush ImageSource="/WpfApplication1;compon ...

  2. html学习笔记之2——多媒体

    一:插件 插件可以通过 <object> 标签或者 <embed> 标签添加在页面中. <object width="400" height=&quo ...

  3. 每天一个linux命令(8):rm

    1.命令简介 rm(Remove file 删除目录或文件)删除文件,对于链接文件,只是删除整个链接文件,而原有文件保持不变. 2.用法 rm [选项]... 文件.. 3.选项 -f, –force ...

  4. 【Android开发坑系列】之窗口管理

    关键知识要点如下(持续更新): WindowManagerService只负责管理Window,不负责图像的绘制: SurfaceFlinger负责图像的合成:

  5. Atitit 华为基本法 attilax读后感

    Atitit 华为基本法 attilax读后感 “精神对物质的比重是三比一” 认可拿破仑的这句格言 在20多年中国商业和企业史上,一个最基本.也是最大的现象就是,为什么"中国制造" ...

  6. Atitit 管理的模式扁平化管理 金字塔 直线型管理 垂直管理 水平管理 矩阵式管理 网状式样管理 多头管理 双头管理

    Atitit 管理的模式扁平化管理  金字塔 直线型管理 垂直管理 水平管理 矩阵式管理 网状式样管理 多头管理 双头管理 1.1. 矩阵管理 1 1.2. 相关信息 矩阵的历史 1 1.3. 基于“ ...

  7. [moosefs] storage class

    chapter 1 moosefs 3.1 storage class 功能的介绍 1.1 什么是storage class 在moosefs中,storage class允许指定文件的chunks存 ...

  8. 禅道项目管理系统整合Selenium IDE的思路

    前两天说用过Selenium IDE产生了一些想法,这里做一些整理. 传统的测试人员管理测试用例,基本都是用Excel.这没什么不好的,也没什么好的.如果通过管理系统来管理用例,相对来说,少了一些简便 ...

  9. 设计模式——proxy代理模式

    目录 概述 定义 角色 为什么会有代理模式? 应用场景 示例 静态代理 例子 动态代理 JDK中生成代理对象的API 代码示例: 代码示例2 Cglib代理 代码示例 AOP(AspectOrient ...

  10. MySQL 表中添加 时间戳 字段

    场景: 有张表的数据需要用同步工具同步至其他库,需要 update_time 时间戳字段 来做增量同步. 解决方法: alter table quant_stk_calc_d_wxcp add upd ...