[Atcoder ARC103D]Robot Arms

Title effect: there $ n-$ points in the plane, ask you configured $ m $ edges (satisfying $ m \ leqslant40 $), so that can be reached from the origin given $ n-$ points (edges must be parallel to the axis) . And the required output direction of each edge, each edge must be used, no solution output $ $ -1. $ n \ leqslant1000 $, the absolute value of the coordinates of a point $ \ leqslant10 ^ 9 $, side length $ \ leqslant10 ^ {12} $

Solution: Because all edges must be used, so that horizontal and vertical coordinates of each point of the added parity, except no solution. If the length is configured found $ 1,2, \ cdots, 2 ^edges meet can reach $ | x | + | y |and $ | x | + | y | \ equiv 1 \ all points pmod2 $, if $ | x | + | y |coupled with a length of just $ 1 $ edges. And found $ 2 ^ n> \ sum \so if considering descending edge, must take the horizontal and vertical coordinates in a direction more phase difference. Such enumeration can be greedy.

Card point: not open $ \ mathrm {long \ long}the coordinate position is not modified

 

C++ Code:

#include <iostream>
#include <algorithm>
#include <cstdio>
const int maxn = 1010,
	X[] = { 1, 0, -1, 0 }, Y[] = { 0, 1, 0, -1 };

int n, x[maxn], y[maxn], w[maxn], idx;
void solve(long long x, long long y) {
	for (int i = 1; i <= idx; ++i) {
		char c;
		if (abs(x) > abs(y))
			if (x < 0) x += w[i], c = 'L';
			else x -= w[i], c = 'R';
		else
			if (y < 0) y += w[i], c = 'D';
			else y -= w[i], c = 'U';
		std::cout << c;
	}
	std::cout.put('\n');
}

int main() {
	std::ios::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) {
		std::cin >> x[i] >> y[i];
		if ((x[i] + y[i] & 1) != (x[1] + y[1] & 1)) {
			std::cout << "-1\n";
			return 0;
		}
	}
	for (int i = 30; ~i; --i) w[++idx] = 1 << i;
	if (!(x[1] + y[1] & 1)) w[++idx] = 1;
	std::cout << idx << '\n';
	for (int i = 1; i < idx; ++i) std::cout << w[i] << ' ';
	std::cout << w[idx] << '\n';
	for (int i = 1; i <= n; ++i) solve(x[i], y[i]);
	return 0;
}

  

Guess you like

Origin www.cnblogs.com/Memory-of-winter/p/11796104.html