eolymp
bolt
Try our new interface for solving problems
Problems

Inherit the Spheres

Inherit the Spheres

In the year \textbf{2xxx}, an expedition team landing on a planet found strange objects made by an ancient species living on that planet. They are transparent boxes containing opaque solid spheres (\textit{\textbf{Figure 1}}). There are also many lithographs which seem to contain positions and radiuses of spheres. \includegraphics{https://static.e-olymp.com/content/93/93fdd81ab1dd6be925733d455cc40d3cfe8b2c4a.jpg} Figure 1. A strange object Initially their objective was unknown, but Professor Zambendorf found the cross section formed by a horizontal plane plays an important role. For example, the cross section of an object changes as in \textit{\textbf{Figure 2}} by sliding the plane from bottom to top. \includegraphics{https://static.e-olymp.com/content/67/67824e3490f76a38d9f63dcc8346da07b43d8bcc.jpg} Figure 2. Cross sections at different positions He eventually found that some information is expressed by the transition of the number of connected figures in the cross section, where each connected .gure is a union of discs intersecting or touching each other, and each disc is a cross section of the corresponding solid sphere. For instance, in \textit{\textbf{Figure 2}}, whose geometry is described in the first sample dataset later, the number of connected figures changes as \textbf{0}, \textbf{1}, \textbf{2}, \textbf{1}, \textbf{2}, \textbf{3}, \textbf{2}, \textbf{1}, and \textbf{0}, at \textbf{z = 0.0000},\textbf{162.0000}, \textbf{167.0000}, \textbf{173.0004}, \textbf{185.0000}, \textbf{191.9996}, \textbf{198.0000}, \textbf{203.0000}, and \textbf{205.0000}, respectively. By assigning\textbf{1} for increment and \textbf{0} for decrement, the transitions of this sequence can be expressed by an \textbf{8}-bit binary number\textbf{11011000}. For helping further analysis, write a program to determine the transitions when sliding the horizontal plane from bottom (\textbf{z = 0}) to top (\textbf{z = 36000}). \InputFile The input consists of a series of datasets. Each dataset begins with a line containing a positive integer, which indicates the number of spheres \textbf{N} in the dataset. It is followed by \textbf{N} lines describing the centers and radiuses of the spheres. Each of the \textbf{N} lines has four positive integers \textbf{X_i}, \textbf{Y_i}, \textbf{Z_i}, and \textbf{R_i} (\textbf{i = 1}, ..., \textbf{N}) describing the center and the radius of the \textbf{i}-th sphere, respectively. You may assume \textbf{1} ≤ \textbf{N} ≤ \textbf{100}, \textbf{1} ≤ \textbf{R_i} ≤ \textbf{2000}, \textbf{0} < \textbf{X_i} - \textbf{R_i} < \textbf{X_i} + \textbf{R_i} < \textbf{4000}, \textbf{0} < \textbf{Y_i - R_i} < \textbf{Y_i + R_i} < \textbf{16000}, and \textbf{0} <\textbf{Z_i - R_i} < \textbf{Z_i + R_i} < \textbf{36000}. Each solid sphere is defined as the set of all points (\textbf{x}, \textbf{y}, \textbf{z}) satisfying \textbf{(x - X_i)^2 + (y - Y_i)^2+ (z - Z_i)^2} ≤ \textbf{R_i^2}. A sphere may contain other spheres. No two spheres are mutually tangent. Every \textbf{Z_i} ± \textbf{R_i} and minimum/maximum\textbf{z} coordinates of a circle formed by the intersection of any two spheres differ from each other by at least \textbf{0.01}. The end of the input is indicated by a line with one zero. \OutputFile For each dataset, your program should output two lines. The first line should contain an integer \textbf{M} indicating the number of transitions. The second line should contain an \textbf{M}-bit binary number that expresses the transitions of the number of connected figures as specified above.
Time limit 1 second
Memory limit 64 MiB
Input example #1
3
95 20 180 18
125 20 185 18
40 27 195 10
1
5 5 5 4
2
5 5 5 4
5 5 5 3
2
5 5 5 4
5 7 5 3
16
2338 3465 29034 710
1571 14389 25019 842
1706 8015 11324 1155
1899 4359 33815 888
2160 10364 20511 1264
2048 8835 23706 1906
2598 13041 23679 618
1613 11112 8003 1125
1777 4754 25986 929
2707 9945 11458 617
1153 10358 4305 755
2462 8450 21838 934
1822 11539 10025 1639
1473 11939 12924 638
1388 8519 18653 834
2239 7384 32729 862
0
Output example #1
8
11011000
2
10
2
10
2
10
28
1011100100110101101000101100
Source ACM Asia - Ehime (Japan) 2004