#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define pii pair<ll, ll>
#define fi first
#define se second
const ll N = 1e5 + 5, inf = 1e18, mod = 1e9 + 7, block = 320, lim = 1 << 16;
int n, m;
int w, h;
int par[N], sz[N];
double length[2005][2005];
string ans[N];
int id[5];
pii corner[4] = {{0, 0}, {w, 0}, {w, h}, {0, h}};
struct circle {
int x, y, r, id;
} a[N];
struct visitor {
int r, e, id;
} v[N];
struct item {
int x, y;
double w;
};
double cal(circle a, circle b) {
double val = 1.0 * sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) - (a.r + b.r);
return max(val, 0.0);
}
void makeset() {
for (int i = 1; i <= n + 4; i++) {
par[i] = i;
sz[i] = 1;
}
}
int find(int u) {
if (u == par[u]) return u;
return par[u] = find(par[u]);
}
void join(int u, int v) {
u = find(u), v = find(v);
if (u != v) {
if (sz[u] < sz[v]) swap(u, v);
sz[u] += sz[v];
par[v] = u;
}
}
bool check(int u, int v) {
u = find(u);
v = find(v);
return (u != v);
}
vector <item> have;
bool cmp(item a, item b) {
return a.w < b.w;
}
bool cmp2(visitor a, visitor b) {
return a.r < b.r;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
if (fopen(".inp", "r")) {
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n >> m >> w >> h;
makeset();
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y >> a[i].r;
a[i].id = i;
}
for (int i = 1; i <= m; i++) {
cin >> v[i].r >> v[i].e;
v[i].id = i;
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
length[i][j] = length[j][i] = cal(a[i], a[j]);
have.push_back({i, j, length[i][j]});
}
length[i][n + 1] = max(0.0, double(h - a[i].y - a[i].r)); // tren
length[i][n + 2] = max(0.0, double(w - a[i].x - a[i].r)); // phai
length[i][n + 3] = max(0.0, double(a[i].y - a[i].r)); // duoi
length[i][n + 4] = max(0.0, double(a[i].x - a[i].r)); // trai
have.push_back({i, n + 1, length[i][n + 1]});
have.push_back({i, n + 2, length[i][n + 2]});
have.push_back({i, n + 3, length[i][n + 3]});
have.push_back({i, n + 4, length[i][n + 4]});
}
sort(have.begin(), have.end(), cmp);
sort(v + 1, v + m + 1, cmp2);
int pointer = 0;
for (int i = 1; i <= m; i++) {
while(pointer < have.size() && have[pointer].w < 2.00 * v[i].r) {
join(have[pointer].x, have[pointer].y);
pointer++;
}
int e = v[i].e;
string s = "";
if (e == 1) {
s += "1";
if (check(n + 1, n + 3) && check(n + 4, n + 3) && check(n + 3, n + 2)) s += "2";
if (check(n + 1, n + 3) && check(n + 2, n + 4) && check(n + 1, n + 2) && check(n + 3, n + 4)) s += "3";
if (check(n + 2, n + 4) && check(n + 1, n + 4) && check(n + 3, n + 4)) s += "4";
}
if (e == 2) {
if (check(n + 1, n + 3) && check(n + 2, n + 3) && check(n + 3, n + 4)) s += "1";
s += "2";
if (check(n + 2, n + 4) && check(n + 2, n + 3) && check(n + 1, n + 2)) s += "3";
if (check(n + 1, n + 3) && check(n + 2, n + 4) && check(n + 1, n + 4) && check(n + 2, n + 3)) s += "4";
}
if (e == 3) {
if (check(n + 1, n + 3) && check(n + 2, n + 4) && check(n + 1, n + 2) && check(n + 3, n + 4)) s += "1";
if (check(n + 2, n + 4) && check(n + 2, n + 3) && check(n + 1, n + 2)) s += "2";
s += "3";
if (check(n + 1, n + 3) && check(n + 1, n + 4) && check(n + 1, n + 2)) s += "4";
}
if (e == 4) {
if (check(n + 2, n + 4) && check(n + 1, n + 4) && check(n + 3, n + 4)) s += "1";
if (check(n + 1, n + 3) && check(n + 2, n + 4) && check(n + 1, n + 4) && check(n + 2, n + 3)) s += "2";
if (check(n + 1, n + 3) && check(n + 1, n + 4) && check(n + 1, n + 2)) s += "3";
s += "4";
}
ans[v[i].id] = s;
}
for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
return 0;
}
Compilation message (stderr)
park.cpp: In function 'int main()':
park.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
park.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |