3A. Shortest path of the king

时间:2024-01-05 22:18:44

给你一个的棋盘,

问:从一个坐标到达另一个坐标需要多少步?
每次移动可以是八个方向。
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
using namespace std;
typedef long long LL;
const LL INF = 0xffffff;
const int maxn = ;
const LL MOD = 1e9+; void solve(int sx,int sy,int ex,int ey)
{
int x = ex - sx;
int y = ey - sy;
int n = min(abs(x), abs(y));
int step = max(abs(x), abs(y)) ;
printf("%d\n", step);
for(int i=; i<=n; i++)
{
if(x > && y > ) puts("RU");
if(x > && y < ) puts("RD");
if(x < && y > ) puts("LU");
if(x < && y < ) puts("LD");
}
n = max(abs(x), abs(y)) - n; for(int i=; i<=n; i++)
{
if( abs(x) > abs(y) && x > ) puts("R");
if( abs(x) > abs(y) && x < ) puts("L");
if( abs(y) > abs(x) && y > ) puts("U");
if( abs(y) > abs(x) && y < ) puts("D");
}
} int main()
{
char str[];
int sx, sy, ex, ey;
scanf("%s", str);
sx = str[] - 'a' + ;
sy = str[] - '';
scanf("%s", str);
ex = str[] - 'a' + ;
ey = str[] - '';
solve(sx, sy, ex, ey); return ;
}

3A. Shortest path of the king