概述
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).
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.
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.
a8 h1
7 RD RD RD RD RD RD RD
/*题意:给一个起点终点算出最短步数到达并打印路径*/
/*思路:最小步数为x或y的差的最大值。走法:能斜着走就斜着走。把如果先判断x轴,那么当判断y轴时特判y相等时直接输出x并换行。*/#include <iostream> #include <cstdio> #include <algorithm> #include <algorithm> #include <cmath> using namespace std; struct node{ int x, y; }nn[100]; int main() { char s, t; char e, n; while(scanf("%c%c", &s, &t) != EOF){ getchar(); scanf("%c%c", &e, &n); int maxn = -1; maxn = max(maxn, abs(s - e)); maxn = max(maxn, abs(t - n)); printf("%dn", maxn); for(int i = 0; i < maxn; i++){ if(s < e){ printf("R"); s++; } else if(s > e){ printf("L"); s--; } if(t == n){ //上面判断的x,所以如果y相等只需要横着走,并换行即可 printf("n"); continue; } else if(t < n){ printf("U"); t++; } else if(t > n){ printf("D"); t--; } printf("n"); } getchar(); } return 0; }
最后
以上就是漂亮路灯为你收集整理的codeforce 3A的全部内容,希望文章能够帮你解决codeforce 3A所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复