#P4760. Cogwheel Machine
Cogwheel Machine
Cogwheel Machine
A very important and complicated machine consists of n wheels, numbered 1, 2, . . . , n. They are actually cogwheels, but the cogs are so small that we can model them as circles on the plane. Every wheel can spin around its center. Two wheels cannot overlap (they do not have common interior points), but they can touch. If two wheels touch each other and one of them rotates, the other one spins as well, as their micro-cogs are locked together.
A force is applied to wheel 1 (and to no other wheel), making it rotate at exactly one turn per minute, clockwise. When two wheels with radii \(r_i\) and \(r_j\) touch, if wheel \(i\) rotates at a rate \(v_i\) (in turns per minute), then wheel \(j\) will rotate at a rate
[ v_j = \frac{r_i}{r_j} \times v_i ]
with the rotation direction reversed. Compute the rates of the remaining wheels’ movement. If a wheel is not connected to wheel 1 through a series of touching wheels, it will not move. You may assume that the machine is not jammed (i.e. the movement is physically possible).
inputFormat
The first line contains an integer n (the number of wheels). Each of the following n lines contains three space‐separated integers x, y and r, where (x, y) represents the center of the wheel and r its radius.
It is guaranteed that no two wheels overlap, and two wheels touch each other if and only if the distance between their centers is exactly equal to the sum of their radii.
outputFormat
For each wheel (from wheel 1 to wheel n), output its rotation speed on a separate line. If the wheel rotates, print the speed as a simplified fraction (if the denominator is 1, output it as an integer) followed by a space and then its rotation direction (clockwise or counterclockwise). If the wheel does not rotate (i.e. it is not connected to wheel 1), output not moving
.
sample
3
0 0 1
2 0 1
4 0 1
1 clockwise
1 counterclockwise
1 clockwise
</p>