首页 > 其他分享 >P9840 [ICPC2021 Nanjing R] Oops, It's Yesterday Twice More

P9840 [ICPC2021 Nanjing R] Oops, It's Yesterday Twice More

时间:2023-11-16 21:46:02浏览次数:35  
标签:P9840 int ICPC2021 Yesterday Twice More

P9840 [ICPC2021 Nanjing R] Oops, It's Yesterday Twice More

注意到最后袋鼠要集中到一个点上,显然先走到四个角落之一再移动到点 \((a,b)\) 是最优的,可以证明,步数一定不超过 \(3(n-1)\)。

因为不知道具体要到哪一个角落里,因此记录 \((a,b)\) 到每个角落的距离并大力分类讨论即可。

#include <bits/stdc++.h>
#define int long long
using namespace std;

int n, a, b;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);

	cin >> n >> a >> b;
	int w, x, y, z;
	w = a + b - 2, x = n * 2 - a - b + 2, z = n - b + 1 + a;
	if (w <= n - 1) {
		for (int i = 2; i <= n; i++) cout << 'U';
		for (int i = 2; i <= n; i++) cout << 'L';
		for (int i = 2; i <= a; i++) cout << 'D';
		for (int i = 2; i <= b; i++) cout << 'R';
	}
	else {
		if (x <= n - 1) {
			for (int i = 2; i <= n; i++) cout << 'D';
			for (int i = 2; i <= n; i++) cout << 'R';
			for (int i = a + 1; i <= n; i++) cout << 'U';
			for (int i = b + 1; i <= n; i++) cout << 'L';
		}
		else {
			if (z <= n - 1) {
				for (int i = 2; i <= n; i++) cout << 'U';
				for (int i = 2; i <= n; i++) cout << 'R';
				for (int i = 2; i <= a; i++) cout << 'D';
				for (int i = b + 1; i <= n; i++) cout << 'L';
			}
			else {
				for (int i = 2; i <= n; i++) cout << 'D';
				for (int i = 2; i <= n; i++) cout << 'L';
				for (int i = a + 1; i <= n; i++) cout << 'U';
				for (int i = 2; i <= b; i++) cout << 'R';
			}
		}
	}
	return 0;
}

标签:P9840,int,ICPC2021,Yesterday,Twice,More
From: https://www.cnblogs.com/George-Pig-Orz/p/17837325.html

相关文章

  • P9847 [ICPC2021 Nanjing R] Crystalfly
    P9847[ICPC2021NanjingR]Crystalfly你说得对,但是刻晴更可爱捏翻译给定一个\(n(1\len\le10^5)\)个节点的树,每个节点上有\(a_i\)只晶蝶。派蒙最初在\(1\)号节点,并获得\(1\)号节点的所有晶蝶,接下来每一秒她可以移动到相邻的节点上并获得节点上的所有晶蝶,但是当她每到......
  • The 2022 ICPC Asia Nanjing Regional Contest(A.Stop, Yesterday Please No More)
    模拟边界(不是袋鼠)移动,通过二维差分维护左上角和右下角,同时注意排除重复的点#include<bits/stdc++.h>usingnamespacestd;#defineendl"\n"typedeflonglongll;constintN=1e3+5;intf[N][N];intmain(){ios::sync_with_stdio(false),cin.tie(0),cout.......
  • Oops, It's Yesterday Once Twice Three times.
    严谨一点讲,这叫广义串并联图方法,即:删一度点,缩二度点,叠合重边。通俗一点讲,叫:把看上去显然的情况做掉答案就出来了[USACO22OPEN]HoofandBrainP按照套路,先考虑没有出边......