Oh Those Rollers
InterviewTime limit1sMemory limit128 MB
Rollers touch when the distance between centers equals the sum of radii. Starting from the roller at the origin, follow the chain to the roller that drives no other and print its coordinates.
- Level
Medium4 of 10
- Topics
- Graph, DFS, Geometry, Implementation
- Solved
- No attempts yet
Problem
A winch has a large steel plate holding rollers. The drive-roller, the ultimate source of power, sits at the origin . The drive-roller turns one other roller, that roller turns another, and so on, so power travels along a chain until the final roller is reached — a roller that is driven but drives no other roller.
Two rollers transmit power only when they touch on the outside: one roller drives another exactly when the distance between their centers equals the sum of their radii. That is, rollers and touch when .
You are given the center coordinates and radius of every roller . Find the coordinates of the last roller in the chain (the roller that is driven but drives no other roller). Every roller except the drive-roller is driven by exactly one other roller.
- ,
Input
- Line 1: a single integer .
- Lines 2 to : line describes roller with three space-separated integers , , and .
Output
- A single line with two space-separated integers: the and coordinates of the last roller in the chain of driven rollers.