"Explanations" Luo Valley P3958 cheese

Portal

Portal1: Luogu

Portal2: LibreOJ

Portal3: Strands

Description

A conventional cheese as its height \ (H \) , its length and width We can be considered infinite, many of the same cheese middle radius of the spherical cavity. We can build in the spatial coordinate system cheese piece, in a coordinate system, the lower surface of the cheese is \ (Z = 0 \) , the upper surface of the cheese is \ (Z = H \) .

Now, under the surface there is a little mouse cheese Jerry, cheese coordinate all know it empty center of the sphere is located. If two or tangent hole intersect, Jerryfrom one run to the other hollow cavity, in particular, if a hole or intersects the tangent to the lower surface, Jerrycan be run into the cavity from the lower surface of the cheese; if a hole or tangential to the upper surface intersecting Jerrythe upper surface of the cheese can go from the cavity.

Located under the surface of the cheese Jerrywondered in without destroying the cheese case, the possibility of using the existing hole on the surface of the cheese to go?

Two space \ (P_1 (x_1, Y_1, Z_1) \) , \ (P_2 (x_2, Y_2, Z_2) \) is the distance formula the following:

\[\operatorname{dist}(P_1, P_2) = \sqrt{(x_1 - x_2) ^ 2 + (y_1 - y_2) ^ 2 + (z_1 - z_2) ^ 2}\]

Input

Each input file contains multiple sets of data.

The first line contains a positive integer \ (T \) , represents the number of sets of data contained in the input file.

Followed by \ (T \) sets of data, each data format is as follows: The first line contains three positive integers \ (n, h \) and \ (R & lt \) , to a space between two separate numbers, representing the number of voids in the cheese, the height of the cavity and the radius of the cheese.

The next \ (n-\) rows, each row containing three integers \ (X, Y, Z \) , with a space between two separate numbers, showing hollow sphere center coordinates \ ((x, y, z ) \) .

Output

\ (T \) row, respectively (T \) \ answer set of data, if the first \ (I \) groups of data, Jerryfrom the upper run to the lower surface of the surface, is output Yes, and if not, the output No(both without the quotes).

Sample Input

3 
2 4 1 
0 0 1 
0 0 3 
2 5 1 
0 0 1 
0 0 4 
2 5 2 
0 0 2 
2 0 4

Sample Output

Yes
No
Yes

Sample Explain

Hint

Data scale and conventions:

For \ (20 \% \) data, \ (n-=. 1,. 1 \ Le H, R & lt \ 10,000 Le \) , the absolute value of the coordinates does not exceed \ (10,000 \) ;

For \ (40 \% \) data, \ (. 1 \ n-Le \ Le. 8,. 1 \ Le H, R & lt \ 10,000 Le \) , the absolute value of the coordinates does not exceed \ (10,000 \) .

For \ (80 \% \) data, \ (. 1 \ n-Le \ Le 1,000,. 1 \ Le H, R & lt \ 10,000 Le \) , the absolute value of the coordinates does not exceed \ (10,000 \) .

For \ (100 \% \) data, \ (. 1 \ n-Le \ Le 1,000,. 1 \ Le H, R & lt \ Le 1,000,000,000, T \ Le 20 is \) , the absolute value of the coordinates does not exceed \ (1,000,000,000 \) .

Solution

This problem disjoint-set. . . . . .

Code

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;

typedef long long LL;
const int MAXN = 1005;
int T;
LL n, h, r, x[MAXN], y[MAXN], z[MAXN], father[MAXN];
inline LL read() {
    char ch = getchar();
    LL x = 0, f = 1;
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while ('0' <= ch && ch <= '9') {
        x = (x << 1) + (x << 3) + ch - '0';
        ch = getchar();
    }
    return x * f;
}
inline LL find(LL x) {//找父亲
    return father[x] == x ? x : find(father[x]);//路径压缩
}
inline LL check(LL p, LL q) {
    if ((x[p] - x[q]) * (x[p] - x[q]) + (y[p] - y[q]) * (y[p] - y[q]) + (z[p] - z[q]) * (z[p] - z[q]) <= r * r * 4) return 1; else return 0;
}
int main() {
    T = read();
    while (T--) {
        n = read(); h = read(); r = read();
        for (LL i = 0; i <= n + 1; i++)
            father[i] = i;
        for (LL i = 1; i <= n; i++) {
            x[i] = read(); y[i] = read(); z[i] = read();
            if (fabs(z[i]) <= r) father[find(i)] = find(0);
            if (fabs(h - z[i]) <= r) father[find(i)] = find(n + 1);
            for (LL j = 1; j < i; j++)
                if (check(i, j)) father[find(j)] = find(i);
        }
        if (find(0) == find(n + 1)) printf("Yes\n"); else printf("No\n");
    }
    return 0;
}

Attachment

Test data Download

Guess you like

Origin www.cnblogs.com/shenxiaohuang/p/11221120.html