13
USGS's seismometers have just detected a major earthquake! Emergency response teams need a quick estimate of the number of people affected. Write a program to compute this estimate.
Your program receives 2 inputs. The first is the details of the earthquake itself. The earthquake modeled as a line segment along which the earth ruptured, along with the critical distance from the fault within which damage could be expected. The second input is a list of the location and population of cities in the area. Your program should compute the number of people living in the affected area, that is the sum of the population of all cities within the critical distance of the fault segment.
Input
First a line describing the earthquake, containing the x,y coordinates of the start and end points of the fault, plus the critical distance. The format is A_x A_y B_x B_y D
. For example:
3.0 3.0 7.0 4.0 2.5
encodes the fault extending from (3.0,3.0) to (7.0,4.0) and a critical distance of 2.5.
Second, one line per city in the area, containing the x,y coordinates of the city and its population. For example:
1.0 1.0 2500
5.0 7.0 8000
3.0 4.0 7500
9.0 6.0 3000
4.0 2.0 1000
Output
The number of people living in the affected area. For the above example only the third and fifth cities are in the danger area, so the output would be
8500
Shortest code wins.
Example 2
0.0 0.0 10.0 0.0 5.0
5.0 4.0 10000
5.0 -4.0 1000
5.0 6.0 100
11.0 2.0 10
-4.0 4.0 1
generates
11010
Does the output have to be an integer, or would
8500.0
be ok for the example? And could we maybe get some more testcases? – Ventero – 2011-05-08T12:21:45.790Also, what is the type of the input? As in, how many decimal places could it have? This is relevant for languages which don't have floating point. – Peter Taylor – 2011-05-08T12:46:36.427
The output needs to be an integer, can't have fractional people. Let's say the input is at most 2 decimal places. – Keith Randall – 2011-05-08T14:33:30.133
Does the critical area extend in a semicircle around the endpoints, or is it just a rectangle? – Peter Olson – 2011-05-08T14:37:36.520
@Peter: It ends in semicircles, so the whole thing is lozenge-shaped. – Keith Randall – 2011-05-08T17:24:38.953