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. Optimizing subroutine calls based on architecture level of called subroutine

    A technique is provided for generating stubs. A processing circuit receives a call to a called funct ...

  2. fork与vfork区别

    1. 地址空间各段拷贝: fork: 内核为子进程生成新的地址空间结构,拷贝父进程的代码段,数据空间,堆,栈到自身的地址空间,但注意:子进程的代码段并不会分配物理空间,而是指向父进程的代码段物理空间, ...

  3. python--tesseract

    tesseract的介绍 我们爬虫会受到阻碍,其中一个便是我们在模拟登陆或者请求一些数据的时候,出现的图形验证码,因此我们需要一种能叫图形验证码识别成文本的技术.将图片翻译成文字一般称为光学文字识别( ...

  4. leetcode 之Candy(12)

    这题的思路很巧妙,分两遍扫描,将元素分别和左右元素相比较. int candy(vector<int> &rattings) { int n = rattings.size(); ...

  5. leetcode 之Reverse Nodes in k-Group(22)

    这题有点繁琐,在更新指针时很容易出错. ListNode *reverseKGroup(ListNode *head, int k) { )return head; ListNode dummy(-) ...

  6. 12:django 模板 内建过滤器

    django 模板 内建过滤器 add{{ value|add:"2" }} 对象的加法,如果都是整数类型,简单的算术加法:如果是列表,则是列表的相加 如果无法执行对象的相加,比如 ...

  7. ZK客户端

    说明:本文为读<从Paxos到Zookeeper 分布式一致性原理与实践>读书笔记 shell操作 Java客户端 原始API pom文件: <dependency> < ...

  8. 在Redis集群中使用pipeline批量插入

    在Redis集群中使用pipeline批量插入 由于项目中需要使用批量插入功能, 所以在网上查找到了Redis 批量插入可以使用pipeline来高效的插入, 示例代码如下: Pipeline p = ...

  9. jenkins构建触发器定时任务Build periodically和Poll SCM【转载】

    转至博客:上海-悠悠 前言 跑自动化用例每次用手工点击jenkins出发自动化用例太麻烦了,我们希望能每天固定时间跑,这样就不用管了,坐等收测试报告结果就行. 一.定时构建语法 * * * * * ( ...

  10. Majority Element——算法课上的一道题(经典)

    Given an array of size n, find the majority element. The majority element is the element that appear ...