1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std;
typedef long long LL; const int N = 1100;
struct node { LL x, y, z; } a[N];
bool cmp(node a, node b) { return (a.z < b.z); } bool tp[N], bt[N]; int fa[N], T, n; LL h, r; int root(int x) { return fa[x]==x?x:root(fa[x]); } bool check(int i, int j) { LL dist = (a[i].x-a[j].x)*(a[i].x-a[j].x) + (a[i].y-a[j].y)*(a[i].y-a[j].y) + (a[i].z-a[j].z)*(a[i].z-a[j].z); return dist <= 4*r*r; }
int main() { scanf("%d", &T); while(T--) { scanf("%d%lld%lld", &n, &h, &r); memset(bt, false, sizeof bt); memset(tp, false, sizeof tp); for(int i=1; i<=n; ++i) scanf("%lld%lld%lld", &a[i].x, &a[i].y, &a[i].z); sort(a+1, a+n+1, cmp); for(int i=1; i<=n; ++i) { if(a[i].z - r <= 0) bt[i] = true; if(a[i].z + r >= h) tp[i] = true; } for(int i=1; i<=n; ++i) fa[i] = i; for(int i=1; i<=n; ++i) { for(int j=i+1; j<=n; ++j) { if(check(i, j)) { fa[root(i)] = root(j); } } }
bool fla = false; for(int i=1; i<=n; ++i) { if(bt[i] && tp[root(i)]) { fla = true; break; } } printf("%s", (fla ? "Yes\n" : "No\n")); } return 0; }
|