AT2282 题解
小学生又双叒叕来写题解啦!
这题就是个小模拟,只要你把路线图画好,再按照你的路线去模拟即可。
有多种方法,但必须是内圈加外圈的形式。
附上我的几何画板弄的路线图:
箭头都标好方向了,自己走一遍。
手动模拟完了吗,那就写代码吧。
送上满分代码:
#include <iostream>
#include <cstdio>
using namespace std;
void mp(int c, char x) //多次输出函数。
//参数是重复输出的次数与输出的内容。
{
for (int i = 1; i <= c; i++) cout << x;
}
int main()
{
int sx, sy, fx, fy;
scanf("%d%d%d%d", &sx, &sy, &fx, &fy);
mp(fx-sx, 'R');
mp(fy-sy, 'U');
mp(fx-sx, 'L');
mp(fy-sy, 'D');
cout << "D";
mp(fx-sx+1, 'R');
mp(fy-sy+1, 'U');
cout << "LU";
mp(fx-sx+1, 'L');
mp(fy-sy+1, 'D');
cout << "R";
printf("\n"); //勿忘祖传换行。
return 0;
}
首发:2022-02-05 21:44:32