Place a flagship in 3D so the maximum weighted Manhattan distance to N ships is minimized, and report that minimum power rounded to six decimals.
Hard8GeometryBinary searchImplementationBrute forceNo attempts yetTime limit5sMemory limit512 MBNear the planet Mars, in a faraway galaxy much like our own, the imperial forces and the rebels are fighting. The rebel fleet has N ships. Ship i sits at the point (xi,yi,zi) and carries a receiver of power pi. The rebels need to send orders from the flagship to every ship, but their budget is tight and they cannot buy a strong transmitter.
If the flagship is placed at (x,y,z), then reaching the ship at (xi,yi,zi) whose receiver has power pi takes a transmitter power of at least
pi∣xi−x∣+∣yi−y∣+∣zi−z∣
Choose the flagship position that minimizes the transmitter power needed to reach every ship, and report that power. The flagship coordinates do not have to be integers.
The first line contains the number of test cases T.
The first line of each test case contains the number of ships N. The next N lines each contain four integers xi, yi, zi and pi separated by single spaces. The first three are the coordinates of ship i and the last one is the power of its receiver. Two or more ships may share the same coordinates.
Limits
For each test case print one line in the following format.
Case #X: Y
X is the number of the test case and Y is the smallest transmitter power that reaches every ship of the fleet. Round Y to six digits after the decimal point and print all six digits even when they are zeros. When the discarded part is exactly one half, round up.
The flagship coordinates need not be integers. If the ships are at (0,0,0), (1,2,0), (3,4,0) and (2,1,0) and every receiver has power 1, a flagship at (1.5,2,0) reaches all of them with transmitter power 3.5. With a single ship the flagship can sit on top of it, so the answer is 0.