mirror of
https://github.com/tiennm99/claoj.git
synced 2026-10-11 12:09:03 +00:00
feat(cpp): add prevoi19_robots (wip)
This commit is contained in:
1 parent
255bcaef5f
commit
adb912f942
1 file changed
+111
@@ -0,0 +1,111 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <climits>
|
||||
using namespace std;
|
||||
|
||||
typedef long long ll;
|
||||
|
||||
struct Point {
|
||||
ll x, y;
|
||||
|
||||
Point(ll x = 0, ll y = 0) : x(x), y(y) {
|
||||
}
|
||||
};
|
||||
|
||||
ll manhattan(const Point &a, const Point &b) {
|
||||
return abs(a.x - b.x) + abs(a.y - b.y);
|
||||
}
|
||||
|
||||
bool isPossible(ll D, const vector<Point> &chargers, const Point &start, ll N) {
|
||||
ll u0 = start.x + start.y;
|
||||
ll v0 = start.x - start.y;
|
||||
ll min_u = u0 - N;
|
||||
ll max_u = u0 + N;
|
||||
ll min_v = v0 - N;
|
||||
ll max_v = v0 + N;
|
||||
|
||||
vector<Point> test_points;
|
||||
|
||||
vector<ll> u_candidates = {min_u, max_u};
|
||||
vector<ll> v_candidates = {min_v, max_v};
|
||||
|
||||
for (const Point &c: chargers) {
|
||||
ll cu = c.x + c.y;
|
||||
ll cv = c.x - c.y;
|
||||
|
||||
u_candidates.push_back(cu - D);
|
||||
u_candidates.push_back(cu + D);
|
||||
v_candidates.push_back(cv - D);
|
||||
v_candidates.push_back(cv + D);
|
||||
}
|
||||
|
||||
u_candidates.push_back(u0);
|
||||
v_candidates.push_back(v0);
|
||||
|
||||
for (ll u: u_candidates) {
|
||||
for (ll v: v_candidates) {
|
||||
if ((u + v) % 2 == 0) {
|
||||
ll x = (u + v) / 2;
|
||||
ll y = (u - v) / 2;
|
||||
test_points.push_back(Point(x, y));
|
||||
} else {
|
||||
ll x1 = (u + v) / 2;
|
||||
ll y1 = (u - v) / 2;
|
||||
test_points.push_back(Point(x1, y1));
|
||||
|
||||
ll x2 = (u + v + 1) / 2;
|
||||
ll y2 = (u - v - 1) / 2;
|
||||
test_points.push_back(Point(x2, y2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const Point &p: test_points) {
|
||||
if (manhattan(p, start) > N) continue;
|
||||
|
||||
bool valid = true;
|
||||
for (const Point &c: chargers) {
|
||||
if (manhattan(p, c) < D) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (valid) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
|
||||
int U;
|
||||
ll N;
|
||||
cin >> U >> N;
|
||||
|
||||
vector<Point> chargers(U);
|
||||
for (int i = 0; i < U; i++) {
|
||||
cin >> chargers[i].x >> chargers[i].y;
|
||||
}
|
||||
|
||||
Point start;
|
||||
cin >> start.x >> start.y;
|
||||
|
||||
ll left = 0;
|
||||
ll right = 4e9;
|
||||
|
||||
while (left <= right) {
|
||||
ll mid = left + (right - left) / 2;
|
||||
|
||||
if (isPossible(mid, chargers, start, N)) {
|
||||
left = mid + 1;
|
||||
} else {
|
||||
right = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
cout << right << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user