#P3958. [NOIP 2017 提高组] 奶酪
[NOIP 2017 提高组] 奶酪
Description
There is a large block of cheese with height , and we may regard its length and width as infinite. Inside the cheese, there are many spherical cavities with the same radius. We can establish a 3D coordinate system in the cheese, where the bottom surface of the cheese is and the top surface is .
Now, there is a little mouse Jerry on the bottom surface of the cheese. He knows the coordinates of the centers of all the cavities. If two cavities are tangent to or intersect each other, then Jerry can run from one cavity to the other. In particular, if a cavity is tangent to or intersects the bottom surface, Jerry can enter the cavity from the bottom surface; if a cavity is tangent to or intersects the top surface, Jerry can go from the cavity to the top surface.
Starting on the bottom surface, Jerry wants to know whether he can reach the top surface by using the existing cavities without damaging the cheese.
The distance between two points and in space is:
$$\mathrm{dist}(P_1,P_2)=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}.$$Input Format
Each input file contains multiple data sets.
The first line contains a positive integer , the number of data sets in the file.
Then follow data sets, each with the following format: The first line contains three positive integers , separated by a space, representing the number of cavities, the height of the cheese, and the radius of each cavity.
The next lines each contain three integers , separated by a space, indicating that the center of a cavity is at .
Output Format
Output lines. For the -th data set, if Jerry can go from the bottom surface to the top surface, output Yes; otherwise, output No.
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
Yes
No
Yes
Hint
【Explanation for Sample I/O 1】

For the first data set, from the cross-sectional view:
- The first cavity is tangent to the bottom surface at .
- The second cavity is tangent to the top surface at .
- The two cavities are tangent at .
Output
Yes.
For the second data set, from the cross-sectional view:
- The two cavities neither intersect nor are tangent.
Output
No.
For the third data set, from the cross-sectional view:
- The two cavities intersect, and they are each tangent to or intersect the top and bottom surfaces.
Output
Yes.
【Constraints】
- For of the testdata, , , and the absolute value of each coordinate does not exceed .
- For of the testdata, , , and the absolute value of each coordinate does not exceed .
- For of the testdata, , , and the absolute value of each coordinate does not exceed .
- For of the testdata, , , , and the absolute value of each coordinate does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号