Sample Input
8 20 2
5 3
4 1
1 2
7 2
10 2
13 3
16 2
19 4
3 10 1
3 5
9 3
6 1
3 10 1
5 3
1 1
9 1
Sample Output
6
2
-1
Main topic:There is a lawn, long as L, W, in its horizontal centerline has n positions can be installed water spray device, each location of the sprinkler device coverage for their own radius ri for the circle. Find out the minimum number of water spray devices required.
Analysis and Summary:The key to this problem is that the transformation according to this figure, the effective coverage of a sprinkler system is the rectangle in the middle of the circle. Therefore, at the same time as input, preprocessing, converted to the left side of the rectangle and the coordinates of the right. This, in fact, translates into a classic interval coverage problem.
This question is basically the same as the area cover question I wrote earlier.
AC Code: #include <stdio.h>
#include<string.h>#include<math.h>#include<algorithm>using namespacestd;intn,f;;DoubleL, W;Doubles, t;structqujian{Doublestart; Doubleend;} ; Qujian a[10005];intCMP (Qujian A,qujian b) {returnA.end >b.end;}intMain () { while(~SCANF ("%D%LF%LF", &n, &l, &w))
while (scanf ("%d%lf%lf", &n, &l, &w) ==3)
//here, add ==3 or ~scanf (), or it will time out { Doublestart=0; F=0; for(inti =0; I < n; i + +) {scanf ("%LF%LF", &s, &t); A[i].start= V-sqrt (R * r-w * w/4); Open square must be double type, here the formula is the Pythagorean a[i].end= v + sqrt (R * r-w * w/4); } sort (A,a+N, CMP); while(start<l) {inti; for(i =0; I < n; i + +) { if(A[i].start <=start&& a[i].end>start) {Start=A[i].end; F++; Break; } } if(i==N) Break; } if(start<l) printf ("-1\n"); Elseprintf"%d\n", F); } return 0;}
UVA 10382-watering Grass (area coverage problem)