Crop Circles
InterviewTime limit1sMemory limit128 MB
Given N circles, count for each circle how many of the other circles it overlaps, using the strict distance-versus-sum-of-radii test.
- Level
Easy3 of 10
- Topics
- Geometry, Brute force, Implementation, Math
- Solved
- No attempts yet
Problem
Bessie and her herd-mates have become extremely territorial. The cows, numbered through , have each staked out a grazing spot in the pasture. Cow claims a circular territory centered at integer coordinates with an integer radius (, , , ).
The cows are a bit greedy and sometimes stake out territory that intrudes on their herd-mates. For each cow, count how many of the other cows' territories overlap hers.
Two territories overlap when the distance between their centers is strictly less than the sum of their radii; that is, cow and cow overlap exactly when
(One territory completely containing another also counts as overlapping.)
As an example, consider these six cows with the indicated locations and radii (don't confuse radius with diameter!):

By visual inspection you can see and count the overlaps.
Note: the test data avoids pathological situations such as tangents, where two circles just barely touch.
Input
- Line 1: a single integer .
- Lines 2 to : three space-separated integers , , and .
Output
- Print lines. Line contains a single integer: the number of other cows' territories that overlap cow 's territory.