标签:void struct memset http ret ioi file std 模拟
把每个坐标拆成二进制位,先不管正负,例如\(27 = 0000000000000000000000000011011_2\),我们从高到低删二进制位,如果这个数存在某一位,那么直接删掉就好了,不然就把除了最后一位之外全部取反。
当然我们优先删\(x, y\)中绝对值大的,因为删绝对值大的剩下的那个数就一定更小,那么这样我们可以保证\(x, y\)都能被删到\(0\),如果不能理解的话手动模拟下就好了。
#include<bits/stdc++.h>
#include<bits/extc++.h>
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define go(x, i) for(register int i = head[x]; i; i = nxt[i])
#define For(i, a, b) for(register int i = (a), i##_end_ = (b); i <= i##_end_; ++ i)
#define FOR(i, a, b) for(register int i = (a), i##_end_ = (b); i >= i##_end_; -- i)
#define debug(x) cout << #x << " = " << x << endl
#define mem(a, b) memset(a, b, sizeof(a))
#define cpy(a, b) memcpy(a, b, sizeof(a))
#define min(a, b) (a < b ? a : b)
#define max(a, b) (b < a ? a : b)
#define inf (0x3f3f3f3f)
#define INF (1e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long long ll;
typedef std::pair<ll, int> PLI;
typedef std::pair<int, int> PII;
typedef long double ldb;
typedef double db;
using namespace std;
const int N = 1e3 + 10;
int n, m, d[N];
struct Point {
int x, y;
}A[N];
void Solve(int x, int y) {
FOR(i, 30, 0) {
int now = 1 << i;
if(abs(x) >= now) {
if(x > 0) x -= now, putchar('R');
else x += now, putchar('L');
}
else if(abs(y) >= now) {
if(y > 0) y -= now, putchar('U');
else y += now, putchar('D');
}
else {
if(abs(x) > abs(y)) {
if(x < 0) x += now, putchar('L');
else x -= now, putchar('R');
}
else {
if(y < 0) y += now, putchar('D');
else y -= now, putchar('U');
}
}
}
if(x != 0 || y != 0) puts("fuck");
}
int main() {
#ifdef ylsakioi
file("d");
#endif
cin >> n; For(i, 1, n) cin >> A[i].x >> A[i].y;
int flag = abs(A[1].x + A[1].y) & 1;
For(i, 2, n) if((abs(A[i].x + A[i].y) & 1) ^ flag) return puts("-1"), 0;
cout << (32 - flag) << endl;
FOR(i, 30, 0) cout << (1 << i) << ' ';
puts(flag ? "" : "1");
if(!flag) For(i, 1, n) ++ A[i].y;
For(i, 1, n) {
Solve(A[i].x, A[i].y);
puts(flag ? "" : "D");
}
return 0;
}
Atcoder Regular Contest 103D Robot Arms
标签:void struct memset http ret ioi file std 模拟
原文地址:https://www.cnblogs.com/brunch/p/10113428.html