Center of Mass of a Firefly Swarm
InterviewTime limit5sMemory limit512 MB
Average the fireflies' positions and velocities to get the swarm's center of mass, then find the closest approach to the origin for t >= 0.
- Level
Easy3 of 10
- Topics
- Math, Geometry, Implementation, Brute force
- Solved
- No attempts yet
Problem
You are watching a swarm of fireflies. Each firefly moves along a straight line at a constant velocity. You stand at the center of the universe, at position . Every firefly has the same mass, and you want to know how close the center of the swarm gets to you.
You know the position and the velocity of every firefly at time , and only times matter. The velocities never change, and the fireflies pass freely through all of space, including through each other and through you. Let be the center of mass of the fireflies at time , and let be the distance between your position and . Find the minimum value of , and the earliest time at which .
Input
The first line contains one integer , the number of test cases. Each test case starts with a line holding one integer , the number of fireflies, followed by lines of the form
x y z vx vy vz
Each of those lines describes one firefly: is its position at time and is its velocity.
Limits
- Every number in the input is an integer.
Output
For each test case, print one line of the form
Case #X: dmin tmin
is the test case number, starting from 1. Print and each rounded to exactly eight digits after the decimal point, padded with zeros when a digit is missing. Round an exact halfway value up. Separate the two values with a single space.
Hint
Given points , their center of mass is the point where