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 ...
随机推荐
- perl登录ssh
use warnings; use strict; use Net::SSH::Perl; my $host = '192.168.255.128'; my $username = 'root'; m ...
- 64_g6
gsettings-desktop-schemas-devel-3.24.0-1.fc26.x..> 22-Mar-2017 20:46 19386 gsf-sharp-0.8.1-27.fc2 ...
- Mongo 配置文件 [www]
Mongo 配置文件 [www] http://blog.chinaunix.net/uid-25206403-id-3510934.html mongodb 安装使用 http://blog.si ...
- C#利用WinRAR实现压缩和解压缩
using System; using Microsoft.Win32; using System.Diagnostics; using System.IO; namespace MSCL { /// ...
- WA时查错点
这篇文章旨在总结可能出错的原因,想到时随时会补充. 查看调试输出语句是否删除 查看数组是否清零 查看是否使用long long 查看是否有的常量应开LL(如1LL << (32) ) 查看 ...
- C中级 MariaDB Connector/C API 编程教程
引言 - 环境搭建 首先开始环境搭建. 主要在Window 10 + Visual Studio 2015 上构建使用 mariadb connector/c api 进行数据操作开发. 为什么选择在 ...
- Office Excel保留两位小数的方法,网上到处乱摘的
今天看到一位朋友的问题就在网上查了下,顺便记下来自己用 =ROUND(A1,2)-(MOD(A1*10^3,20)=5)*10^(-2)
- php-cgi segmentation fault nginx
谷歌.百度了一堆后,无果. yum安装软件也报segmentation fault 果断重装系统吧
- 解决Windows10与Ubuntu系统时间不一致问题
前言: 安装完windows与Ubuntu双系统之后会发现windows与Ubuntu时间不一致.这是硬件时间都一样的情况下,Ubuntu使用的是UST,Windows使用的是CST.要解决该问题就要 ...
- ViewPager单页显示3个item
原文地址:https://github.com/hongyangAndroid/MagicViewPager/wiki MagicViewPager 单页显示3个Item的ViewPager炫酷切换效 ...