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.
Examples
a8
h1
7
RD
RD
RD
RD
RD
RD
RD cf此题地址http://codeforces.com/problemset/problem/3/A 这里学到了string这个东西。比如,string a; a[0]="adasdasd",第一次知道还有这种操作,一位存一个字符串,那么就简单多了。
那么使用while模拟就好了,一直接近终点。肯定尽量先斜着走。while根据两者的位置分成好几种情况。根据ASCLL码,直接++,--就好了,不用再变成数字了。string s。s[0],s[1]直接++--就好了,直到等于e[0],e[1]。
使用一个tot来计数,此为总步数。
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
string map[];
string s,e;
int main()
{
int tot=;
cin>>s;
cin>>e;
while(s[]<e[]&&s[]<e[])
{
s[]++;s[]++;
map[tot++]="RU";
}
while(s[]<e[]&&s[]>e[])
{
s[]++;s[]--;
map[tot++]="RD";
}
while(s[]>e[]&&s[]<e[])
{
s[]--;s[]++;
map[tot++]="LU";
}
while(s[]>e[]&&s[]>e[])
{
s[]--;s[]--;
map[tot++]="LD";
}
while(s[]==e[]&&s[]>e[])
{
s[]--;
map[tot++]="D";
}
while(s[]==e[]&&s[]<e[])
{
s[]++;
map[tot++]="U";
}
while(s[]==e[]&&s[]<e[])
{
s[]++;
map[tot++]="R";
}
while(s[]==e[]&&s[]>e[])
{
s[]--;
map[tot++]="L";
}
cout<<tot<<endl;
for(int i=;i<tot;i++)
cout<<map[i]<<endl;
}
A - Shortest path of the king (棋盘)的更多相关文章
-
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 ...
-
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 ...
-
3A. Shortest path of the king
给你一个的棋盘, 问:从一个坐标到达另一个坐标需要多少步? 每次移动可以是八个方向. #include <iostream> #include <cmath> #inclu ...
-
Codeforces Beta Round #3 A. Shortest path of the king
标题效果: 鉴于国际棋盘两点,寻求同意的操作,是什么操作的最小数量,在操作过程中输出. 解题思路: 水题一个,见代码. 以下是代码: #include <set> #include < ...
-
Shortest path of the king
必须要抄袭一下这个代码 The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose h ...
-
CF3A Shortest path of the king
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, becaus ...
-
node搜索codeforces 3A - Shortest path of the king
发一下牢骚和主题无关: 搜索,最短路都可以 每日一道理 人生是洁白的画纸,我们每个人就是手握各色笔的画师:人生也是一条看不到尽头的长路,我们每个人则是人生道路的远足者:人生还像是一块神奇的土地 ...
-
CF3A 【Shortest path of the king】
一句话题意:在8 * 8的棋盘上,输出用最少步数从起点走到终点的方案 数据很小,可以广搜无脑解决 定义数据结构体 struct pos{ int x,y,s; //x.y表示横纵坐标,s表示步数 ]; ...
-
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 ...
随机推荐
-
夺命雷公狗ThinkPHP项目之----企业网站8之栏目的添加完善(无限极分类的完成)
我们刚才只是完成了添加的一部分,但是我们的上级分类也不能永远都是只有一个死的嘛,所以我们需要对她进行修改: 我们先将add方法里面的数据查出来再说: 然后在模板页进行遍历: 展示效果如下所示: 虽然是 ...
-
overfit &; underfit
原文:http://blog.csdn.net/yhdzw/article/details/22733317 过拟合:1)简单理解就是训练样本的得到的输出和期望输出基本一致,但是测试样本输出和测试样本 ...
-
机器学习&;&;数据挖掘之一:决策树基础认识
决策树入门篇 前言:分类是数据挖掘中的主要分析手段,其任务就是对数据集进行学习并构造一个拥有预测功能的分类模型,用于预测未知样本的类标号,把类标号未知的样本按照某一规则映射到预先给定的类标号中. 分类 ...
-
部署statspack工具(二)之解决方案2
解决方案二:在emp2的empno列上面创建索引,再执行share_pool_sql_1.sh脚本,查看sp报告 8.1在emp2的empno列上创建索引 sys@TESTDB12>create ...
-
base64转码,解码方法
function Base64() { // private property _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr ...
-
uniDBGrid实行多选表格行
http://blog.csdn.net/shuiying/article/details/11374655 uniDBGrid本身是支持checkBox多选的,但必须是Boolean的字段才行,只要 ...
-
u3d中的INput
属性 属性: 功能: 轴 (Axes) 包含当前工程的所有定义的输入轴:数目 (Size) 该工程中不同输入轴的数量,元素 0.1.... 是要修改的特定的轴. 名称 (Name) 在游戏启动器中以及 ...
-
编译器C1001问题
https://ask.csdn.net/questions/184495 http://blog.sina.com.cn/s/blog_7822ce750100szed.html
-
[xsy2880]取石子游戏
题意:有$n$堆石子,每堆石子数量相同,以质因数分解给出,不停地从$1$到$n$依次拿石子,使得取完后石子个数为原来的因数(不能不取),当一堆只剩$1$个时结束,问在每堆石子结束的方案数 记石子个数为 ...
-
django国际化总结
转:http://blog.csdn.net/ybdesire/article/details/46806739