GCJ1C09B  Center of Mass
Problem
You are studying a swarm of N fireflies. Each firefly is moving in a straight line at a constant speed. You are standing at the center of the universe, at position (0, 0, 0). Each firefly has the same mass, and you want to know how close the center of the swarm will get to your location (the origin).
You know the position and velocity of each firefly at t = 0, and are only interested in t ≥ 0. The fireflies have constant velocity, and may pass freely through all of space, including each other and you. Let M(t) be the location of the center of mass of the N fireflies at time t. Let d(t) be the distance between your position and M(t) at time t. Find the minimum value of d(t), d_{min}, and the earliest time when d(t) = d_{min}, t_{min}.
Input
The first line of input contains a single integer T, the number of test cases. Each test case starts with a line that contains an integer N, the number of fireflies, followed by N lines of the form
x y z vx vy vz
Each of these lines describes one firefly: (x, y, z) is its initial position at time t = 0, and (vx, vy, vz) is its velocity.
Output
For each test case, output
Case #X: d_{min} t_{min}
where X is the test case number, starting from 1. Any answer with absolute or relative error of at most 10^{6} will be accepted.
Limits
All the numbers in the input will be integers.
1 ≤ T ≤ 100
The values of x, y, z, vx, vy and vz will be between 5000 and 5000, inclusive.
Large dataset
3 ≤ N ≤ 500
Sample
Input 
Output 
3 
Case #1: 0.00000000 1.00000000 
Notes
Given N points (x_{i}, y_{i}, z_{i}), their center of the mass is the point (x_{c}, y_{c}, z_{c}), where:
x_{c} = (x_{1} + x_{2} + ... + x_{N}) / N y_{c} = (y_{1} + y_{2} + ... + y_{N}) / N z_{c} = (z_{1} + z_{2} + ... + z_{N}) / N
hide comments
maurice37:
20151215 05:35:51
Everyone getting the correct output but wrong answer, try using printf("%.8f") 

gamer496:
20150623 08:41:05
final test is wrong last input line has only five inputs 

da jOkEr:
20150615 19:26:59
my 70th... Can be Solved using 2 approaches.. my 70th :) 

Anmol Garg:
20141008 14:13:23
100th! :D 

Vikas Yadav:
20140604 20:01:57
easy one!!! My 50th :D 

Ashwini:
20140115 10:05:51
good ques. silly mistake cost me 4 wa. AC finally 

piyush:
20130809 17:56:58
finally ac :) :) 

apsdehal:
20130628 07:05:12
Last edit: 20130630 08:11:17 

::
20130620 12:54:40
AC ! thanx Tjandra 

ABHISHEK004:
20130620 11:02:49
aahh..!!! finally accepted after many WA... 
Added by:  Shafaet 
Date:  20130507 
Time limit:  1s20s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 
Resource:  Google Codejam 2009, Round 1C, Problem B 