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 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 水题的更多相关文章
- Codeforces Beta Round #3 A. Shortest path of the king
标题效果: 鉴于国际棋盘两点,寻求同意的操作,是什么操作的最小数量,在操作过程中输出. 解题思路: 水题一个,见代码. 以下是代码: #include <set> #include < ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Beta Round #70 (Div. 2)
Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #5 B. Center Alignment 模拟题
B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- 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]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
随机推荐
- java基础 运算符
算数运算符 加号:在操作数值.字符.字符串时其结果是不同的,当两个字符相加得到的是ASCII码表值, 当两个字符串相加时表示将两个字符串连接在一起,从而组成新的字符串. 除号:整数在使用除号操作时,得 ...
- python基础===函数的几个要点
函数 可接受任意数量参数的函数 位置参数 和 关键字参数 为了能让一个函数接受任意数量的位置参数,可以使用一个*参数. def avg(first, *r): return (first + s ...
- Django===django工作流
通过一张图来总结一下Django 的处理过程: URL 组成: 协议类型: HTTP/HTTPS HTTP 协议(HyperText Transfer Protocol,超文本传输协议)是用于从WWW ...
- edittext 的一个案例
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...
- 12:django 模板 内建过滤器
django 模板 内建过滤器 add{{ value|add:"2" }} 对象的加法,如果都是整数类型,简单的算术加法:如果是列表,则是列表的相加 如果无法执行对象的相加,比如 ...
- linux命令(36):which命令
我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索: which 查看可执行文件的位置. whereis 查看文件的位置. ...
- 自动化运维之saltstack的使用安装
SaltStack 简介 SaltStack是一个服务器基础架构集中化管理平台,具备配置管理.远程执行.监控等功能,基于Python语言实现,结合轻量级消息队列(ZeroMQ)与Python第三方模块 ...
- Rotate Image——数学相关
You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). ...
- "GrabCut" - Interactive Foreground Extraction using Iter
转载自:http://blog.csdn.net/zouxy09/article/details/8534954 有源代码的博客:http://www.cnblogs.com/xrwang/archi ...
- 微信小程序radio组件 - 如何改变默认样式大小?
今天在写小程序的时候用到radio组件,但是很懊恼并未提供修改radio组件大小属性,第一感觉准备用css width , height 改变radio的大小,但是怎么搞也无法改变. 但是又不愿意搞个 ...