-->
当前位置:首页 > 题库

PROGRAMMING:Sprinkler

Luz5年前 (2021-05-10)题库449
There are n sprinkler heads in the lawn of L meters long and W meters wide. Each sprinkler is installed on the center line of the lawn (w / 2m from each side). We know the location of each sprinkler (the distance from the left end of the lawn centerline) and the range of irrigation it can cover.
Excuse me: if you want to water the whole lawn at the same time, at least how many sprinklers need to be turned on?
###Input format:
The input contains several sets of test data.
An integer t in the first line represents the number of data groups.
The first row of each group of data is the value of integers n, l and W, where n ≤ 10 000.
The next n rows, each of which contains two integers, give the location and radius of a sprinkler.
The schematic diagram shown in Figure 1 is the situation described by the first set of data input by the sample.
![ ttt.jpg](~/a3537127-8297-4fce-9ff1-4e0effc49670.jpg)
Figure 1
###Output format:
Output a number for each group of test data to indicate the minimum number of sprinklers needed to irrigate the whole lawn. If all sprinklers are turned on and the whole lawn cannot be watered, output - 1.
###Input example:
```in
three
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
```
###Output example:
```out
six
two
-1
```
###Data range and tips:
For 100% data, n ≤ 15000.







answer:If there is no answer, please comment
[problem solving ideas]
① Read in the data and calculate S[i].a=x-sqrt(r*r-(w/2)*(w/2))。
S[i].b=x+sqrt(r*r-(w/2)*(w/2))。
② According to s [i]. A, it is arranged from small to large.
③ Each interval is processed from left to right.