UVA 10382-watering Grass (area coverage problem)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.