The Agglomerator
Time limit3sMemory limit256 MB
Simulate moving circular droplets that merge on contact with area-weighted position and velocity, and report the final count and last merge time.
- Level
Medium6 of 10
- Topics
- Simulation, Math, Geometry
- Solved
- No attempts yet
Problem
You simulate the motion of droplets in a plane. Each droplet is a circle of some size that moves at a constant velocity. The moment two circles touch, they agglomerate into a single circular droplet whose area is the sum of the two areas. The new droplet's center is the area weighted average of the two centers at the moment of contact, and its velocity is the area weighted average of the two velocities.

The figure illustrates the process. In the top panel, a droplet of radius 4 centered at moves with velocity toward a stationary droplet of radius 3 centered at the origin. The two circles touch at time , which is the middle panel.
At that moment the droplet of radius 4 is centered at . The two areas are and , so the new droplet has area and radius 5. The coordinate of the agglomerated droplet is and the coordinate is . The same calculation gives the velocity .
Given the initial configuration, simulate the motion until no further agglomeration can occur. Report how many droplets remain and the time of the last agglomeration.
Every test satisfies the following:
- No two of the original droplets touch.
- When an agglomeration forms a new droplet, that droplet touches no other droplet at the moment it is formed. It is at least away from touching any of them.
- No two droplets ever pass each other with a single point of intersection. Growing or shrinking the radius of any droplet by does not change whether it collides with another droplet.
- No two pairs agglomerate at exactly the same time. Consecutive agglomerations are at least apart in time.
- No agglomeration happens after time .
- The exact value of the answer is at least away from the midpoint of two consecutive multiples of , so double precision arithmetic rounds it to six decimal places unambiguously.
Input
The first line contains the original number of droplets ().
Each of the next lines contains five integers , , , , separated by spaces: the coordinate of the center, the coordinate of the center, the component of the velocity, the component of the velocity, and the radius. These satisfy and .
Output
Print a single line with two values and separated by one space. is the number of droplets in the final configuration, and is the time at which the final agglomeration occurred.
Round to six decimal places and print exactly six digits after the decimal point. If no agglomeration occurs, equals the original number of droplets and is 0.000000.