The meaning of problems
Given \ (n \) points, you need to find a suitable \ (m \) and \ (D_1, d_2, ..., D_m \) , so that each one starting from the origin to go to the four directions \ (d_i \) units, eventually reaching the \ ((x_t, Y_t) \) . Output \ (m \) and \ (D \) array; for \ (t = 1 \ to n \) output direction.
\ (n-\ Leq. 3 ^ 10 \) , coordinate range \ (10 ^ 9 \)
answer
If the point \ ((x_t, Y_t) \) , \ (x_t + Y_t \) of different parity that no solution
If \ (x_t + y_t \) is even, let us \ (D_1. 1 = \) , thus converted into \ (x_t + y_t \) is an odd number.
Odd how to do? Binary structure.
A : Consider \ (d (k) = { 1, 2, 4, ..., 2 ^ k} \) such sets, can go all \ (| x | + | y | \ leq 2 ^ {k -1 + 1} \) point (and an odd)
Proof: https://blog.csdn.net/qq_37555704/article/details/83217444#_14 here moved the map.
For \ (d (k) - d (k-1) \) region (the new zone), will go directly to step (above red to violet)
For the original area can be reached, we can go inside from the inside.
Two : Consider how to find solutions.
Proof: \ (D (K) \) can come to a point satisfies \ (\ min (| x | , | y |) \ leq 2 ^ k-1 \)
Most probably prove the value \ (| = 2 ^ k \ x | = 2 ^ k-1, | | y) taken to the adjusted found not preferable.
As long as we each from \ (d (k) \) went \ (d (k-1) \) can be, to \ (d (0) \) when will succeed
By drawing the analysis, each of the large absolute value can be reduced from \ (d (k) \) come \ (D (. 1-K) \) .
Then the problem is gone. There are above us \ (d (k) \) went \ (d (k-1) \) , is actually the other way around, so pay attention to the letter output negated.
#include <algorithm>
#include <cstdio>
using namespace std;
const int N = 1010;
int n, m, x[N], y[N], d[N];
bool tg[N];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%d%d", x + i, y + i);
tg[(x[i] + y[i]) & 1] = 1;
}
if(tg[0] & tg[1]) return puts("-1") & 0;
if(tg[0]) d[++ m] = 1;
for(int i = 30; ~ i; i --) d[++ m] = 1 << i;
printf("%d\n", m);
for(int i = 1; i <= m; i ++) printf("%d%c", d[i], " \n"[i == m]);
for(int i = 1; i <= n; i ++, putchar('\n')) {
for(int j = 1; j <= m; j ++) {
if(abs(x[i]) > abs(y[i])) {
if(x[i] > 0) x[i] -= d[j], putchar('R');
else x[i] += d[j], putchar('L');
} else {
if(y[i] > 0) y[i] -= d[j], putchar('U');
else y[i] += d[j], putchar('D');
}
}
}
return 0;
}