Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
27961 gaochunzhen 【BJ】T1 C++ 通过 100 578 MS 288 KB 2257 2024-03-31 16:51:51

Tests(23/23):


#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1009; struct node { int x, y; } a[N], b[N]; double dis(node x, node y) { ll dx = x.x - y.x, dy = x.y - y.y; return sqrtl(dx * dx + dy * dy); } int n, m, r[N], p1[N], p2[N]; namespace sub1 { struct DSU { int fa[N], tot; void init() { for (int i = 1; i <= n; i++) fa[i] = i; tot = n; } int get(int x) { while (x != fa[x]) x = fa[x] = fa[fa[x]]; return x; } void merge(int x, int y) { x = get(x), y = get(y); if (x != y) fa[y] = x, tot--; } } dsu; int sgn(int x) {return (x ? (x > 0 ? 1 : -1) : 0);} void Main() { dsu.init(); for (int _i = 1; _i <= n; _i++) { for (int _j = _i + 1; _j <= n; _j++) { int i = p1[_i], j = p1[_j], k; if (dsu.get(i) == dsu.get(j)) continue; int fl = 1; ll A = a[i].y - a[j].y, B = a[j].x - a[i].x; ll C = -(A * a[i].x + B * a[i].y); for (int _k = 1; _k <= m; _k++) { k = p2[_k]; ll T = A * b[k].x + B * b[k].y + C; if (T * T <= r[k] * r[k] * (A * A + B * B)) { ll _A = a[i].x - b[k].x, _B = a[i].y - b[k].y; ll _C = b[k].x * (b[k].x - a[i].x) + b[k].y * (b[k].y - a[i].y) - r[k] * r[k]; if (sgn(_A * a[i].x + _B * a[i].y + _C) != sgn(_A * a[j].x + _B * a[j].y + _C)) { fl = 0; break; } } } if (fl) dsu.merge(i, j); } } printf("%d\n", dsu.tot - 1); } } int main() { srand(time(0)); scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d", &a[i].x, &a[i].y); p1[i] = i; } for (int i = 1; i <= m; i++) { scanf("%d%d%d", &b[i].x, &b[i].y, &r[i]); p2[i] = i; } random_shuffle(p1 + 1, p1 + n + 1), random_shuffle(p2 + 1, p2 + m + 1); sub1::Main(); return 0; }


测评信息: