#P16616. [GKS 2017 #A] Two Cubes

    ID: 16571 Type: RemoteJudge 2000ms 1024MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2017并查集二分图Google Kick Start

[GKS 2017 #A] Two Cubes

题目描述

"Look at the stars, look how they shine for you." - Coldplay, "Yellow"

In a galaxy far, far away, there are many stars. Each one is a sphere with a certain position (in three-dimensional space) and radius. It is possible for stars to overlap each other.

The stars are so incredibly beautiful to you that you want to capture them forever! You would like to build two cubes of the same integer edge length, and place them in space such that for each star, there is at least one cube that completely contains it. (It's not enough for a star to be completely contained by the union of the two cubes.) A star is completely contained by a cube if no point on the star is outside the cube; a point exactly on a cube face is still considered to be inside the cube.

The cubes can be placed anywhere in space, but they must be placed with their edges parallel to the coordinate axes. It is acceptable for the cubes to overlap stars or each other.

What is the minimum integer edge length that allows you to achieve this goal?

输入格式

The input starts with one line containing exactly one integer TT, which is the number of test cases. TT test cases follow.

Each test case begins with a line containing an integer, NN, representing the number of stars.

This is followed by NN lines. On the iith line, there are 4 space-separated integers, XiX_i, YiY_i, ZiZ_i and RiR_i, indicating the (X,Y,Z)(X, Y, Z) coordinates of the center of the ithi^{th} star, and the radius of the ithi^{th} star.

输出格式

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the minimum cube edge length that solves the problem, as described above.

3
3
1 1 1 1
2 2 2 1
4 4 4 1
3
1 1 1 2
2 3 4 1
5 6 7 1
3
1 1 1 1
1 1 1 1
9 9 9 1
Case #1: 3
Case #2: 5
Case #3: 2

提示

In the first test case, one solution is to place two cubes with an edge length of 33 such that their corners with minimum (x,y,z)(x, y, z) coordinates are at (0,0,0)(0, 0, 0) and (3,3,3)(3, 3, 3).

In the second test case, one solution is to place two cubes with an edge length of 55 such that their corners with minimum (x,y,z)(x, y, z) coordinates are at (1,1,1)(-1, -1, -1) and (1,2,3)(1, 2, 3).

Limits

1T1001 \le T \le 100

108Xi108-10^8 \le X_i \le 10^8, for all i.

108Yi108-10^8 \le Y_i \le 10^8, for all i.

108Zi108-10^8 \le Z_i \le 10^8, for all i.

1Ri1081 \le R_i \le 10^8, for all i.

Small dataset (Test set 1 - Visible)

2N162 \le N \le 16.

Large dataset (Test set 2 - Hidden)

2N20002 \le N \le 2000.