A. Shortest path of the king

题目连接:

http://www.codeforces.com/contest/3/problem/A

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

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.

Sample Input

a8

h1

Sample Output

7

RD

RD

RD

RD

RD

RD

RD

Hint

题意

给你一个8*8的棋盘

给你一个起始点和终点,让你输出一个最短的路径从起点到终点。

这个点可以朝着8个方向走。

题解:

显然优先考虑斜着走,然后不停朝着终点靠就行了。

无脑bfs也是兹瓷的,反正数据范围这么小。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 2005;
string s,s1;
string ans[maxn];
int tot = 0;
int main()
{
cin>>s;
cin>>s1;
while(s[0]<s1[0]&&s[1]<s1[1])s[0]++,s[1]++,ans[tot++]="RU";
while(s[0]<s1[0]&&s[1]>s1[1])s[0]++,s[1]--,ans[tot++]="RD";
while(s[0]>s1[0]&&s[1]<s1[1])s[0]--,s[1]++,ans[tot++]="LU";
while(s[0]>s1[0]&&s[1]>s1[1])s[0]--,s[1]--,ans[tot++]="LD";
while(s[0]<s1[0])s[0]++,ans[tot++]="R";
while(s[0]>s1[0])s[0]--,ans[tot++]="L";
while(s[1]<s1[1])s[1]++,ans[tot++]="U";
while(s[1]>s1[1])s[1]--,ans[tot++]="D";
cout<<tot<<endl;
for(int i=0;i<tot;i++)
cout<<ans[i]<<endl;
}

Codeforces Beta Round #3 A. Shortest path of the king 水题的更多相关文章

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

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

  2. Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题

    B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfo ...

  3. Codeforces Beta Round #9 (Div. 2 Only) A. Die Roll 水题

    A. Die Roll 题目连接: http://www.codeforces.com/contest/9/problem/A Description Yakko, Wakko and Dot, wo ...

  4. Codeforces Beta Round #5 A. Chat Server's Outgoing Traffic 水题

    A. Chat Server's Outgoing Traffic 题目连接: http://www.codeforces.com/contest/5/problem/A Description Po ...

  5. Codeforces Beta Round #70 (Div. 2)

    Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...

  6. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  7. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  8. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  9. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

随机推荐

  1. Python学习笔记 - day11 - Python操作数据库

    MySQL的事务 MySQL的事务支持不是绑定在MySQL服务器本身,而是与存储引擎相关,MySQL的两种引擎如下: 1.MyISAM:不支持事务,用于只读程序提高性能 2.InnoDB:支持ACID ...

  2. 自动化测试===requests+unittest+postman的接口测试

    postman是一个跨平台的接口测试工具,下载链接在这里:https://www.getpostman.com/ unittest是一个单元测试框架,python中安装:pip install uni ...

  3. Python爬虫之百度API调用

    调用百度API获取经纬度信息. import requests import json address = input('请输入地点:') par = {'address': address, 'ke ...

  4. HTML5API(2)

    四.文件API 1.概述 H5允许JS有条件的读取客户端文件 允许读取的文件:1.待上传的文件2.拖进浏览器的文件 多文件上传设置属性multiple 过滤上传文件类型 设置accept属性 acce ...

  5. IIS配置PHP环境(快速最新版)(转载+自创)

    (参考转载的) 我们知道php配置有几种: 1.CGI方式加载PHP环境,通常就是IIS里面配置解释器为php.exe,早期比较常见,目前使用较少. 特点是:稳定,但效率太低. 2.ISAPI方式加载 ...

  6. [New learn]讲解Objective-c的block知识-实践

    1.简介 在之前的文章[New learn]讲解Objective-c的block知识中介绍了block的相关知识.本章中我们将以一个实际例子来简单介绍一下block如何代替代理. 2.原有通过代理实 ...

  7. C++内存管理(转)

    C++内存管理比较好的文章,参考链接如下: C++内存管理

  8. django “如何”系列5:如何编写自定义存储系统

    如果你需要提供一个自定义的文件存储-一个常见的例子便是在远程系统上存储文件-你可以通过定义一个自己的存储类来做这件事情,你将通过一下步骤: 你自定义的存储系统一定是django.core.files. ...

  9. redis之(三)redis的数据类型

    [一]字符串类型(基本数据类型) --->字符串类型是redis的最基本的数据类型 --->能存储任何形式的字符串,(用户邮箱,json化的对象,一张图片) --->一个字符串类型的 ...

  10. redis之(二)redis单机的安装,配置,启动,关闭

    [1]下载redis压缩包,解压,编译