| Problem 152 - Tree's a Crowd, Explanations |
Subtlety is going to die soon...
For each tree, get all the other trees, compute the closest neighbour and add a point to the correct category according to the distance between them.
Oh! It was THAT simple?
Closest trees further or equal than 10 units don't enter any category.
Don't always compute the square. One time is enough!
If you are in trouble with the multi-entry input, read my how to read input.
Write a program that will read in the parameters of up to 5000 trees
and determine how many of them have closest neighbours that are less
than 1 unit away, how many with closest neighbours 1 or more but less
than 2 units away, and so on up to those with closest neighbours 9 or
more but less than 10 units away. Thus if
is the
distance between the i'th point and its nearest neighbour(s) and
, with j and k integers and k = j+1, then
this point (tree) will contribute 1 to the j'th bin in the histogram
(counting from zero). For example, if there were only two points 1.414
units apart, then the histogram would be 0, 2, 0, 0, 0, 0, 0, 0, 0, 0.
Input will consist of a series of lines, each line consisting of 3 numbers in the range [0, 255]. The file will be terminated by a line consisting of three zeroes.
Output will consist of a single line containing the 10 numbers representing the desired counts, each number right justified in a field of width 4.
10 10 0 10 10 0 10 10 1 10 10 3 10 10 6 10 10 10 10 10 15 10 10 21 10 10 28 10 10 36 10 10 45 0 0 0
2 1 1 1 1 1 1 1 1 1