奶酪
题目链接:
题目分析:
并查集维护联通,最好乘起来防止掉精度
代码:
#include<bits/stdc++.h>
#define int long long
#define eps 1e-8
#define N (5000 + 10)
using namespace std;
inline int read() {
int cnt = 0;
int f = 1; char c = getchar();
while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
while (isdigit(c)) {cnt = (cnt << 3) + (cnt << 1) + (c ^ 48); c = getchar();}
return cnt * f;
}
int n, T, fa[N];
double h, r;
int get_fa(int x) {return (fa[x] == x) ? x : fa[x] = get_fa(fa[x]);}
////int get_fa(int x) {return fa[x];}
struct node {
double x, y, z;
}a[N];
inline int Pow(int x) {return x * x;}
bool cmp(node a, node b) {
return r * r * 4 >= Pow(a.x - b.x) + Pow(a.y - b.y) + Pow(a.z - b.z);
}
signed main() {
T = read();
while (T--) {
n = read(), h = read(), r = read();
for (register int i = 1; i <= n + 2; ++i) fa[i] = i;
// read(n), read(h), read(r);
// for (register int i = 1; i <= n + 2; ++i) cout<<fa[i]<<" ";
for (register int i = 1; i <= n; ++i) {
a[i].x = read(), a[i].y = read(), a[i].z = read();
if (a[i].z - r <= 0) fa[get_fa(i)] = n + 1;
if (a[i].z + r >= h) fa[get_fa(i)] = n + 2;
}
for (register int i = 1; i <= n; ++i)
for (register int j = i + 1; j <= n; ++j) {
if (cmp(a[i], a[j])) {
int fx = get_fa(i), fy = get_fa(j);
if (fx == fy) continue;
fa[fx] = fy;
}
}
if (get_fa(n + 1) != get_fa(n + 2)) {printf("No\n"); continue;}
else printf("Yes\n");
}
return 0;
}