Water spraying Device (ii)
Time limit: Ms | Memory Limit: 65535 KB
Difficulty: 4
Describe
There is a lawn, transverse long w, longitudinal length is H, in its horizontal center line at different locations with N (n<=10000) point-like water spray device, each water spray device I spray the effect is that it is the center radius of the RI is wetting. Please select as few water spray devices as possible in the given sprinkler system to moisten the entire lawn.
Input
The first line enters a positive integer n to indicate a total of n test data.
The first line of each set of test data has three integers n,w,h,n indicates a total of n water spray devices, W represents the transverse length of the lawn, and H indicates the longitudinal length of the lawn.
In the subsequent n rows, there are two integers, Xi and ri,xi, which represent the horizontal axis of the first water sprinkler (0 on the left), and the RI represents the radius of the circle that the water spray device can cover.
Output
Each set of test data outputs a positive integer that indicates how many water jets are required, each of which has a single row.
If there is no solution that can damp the whole lawn, output 0.
Sample input
2
2 8 6
1 1
4 5
2 10 6
4 5
6 5
Sample output
1
2
Source
The competition for Algorithmic Arts and Informatics
Uploaded by
Zhang Yunzun
The interval coverage problem on the line segment. Really no language, in Csdn hair a code also have to turn over the wall ...
#include <stdio.h>#include <string.h>#include <math.h>#include <algorithm>#define MAXN 10010structNode {DoubleLeft, right;} ARR[MAXN];BOOLCMP (Node A, Node B) {returnA.left < B.left;}intMain () {//Freopen ("Data.in", "R", stdin); intNcase, id, result;intN, W, h, X, R;scanf("%d", &ncase); while(ncase--) {scanf("%d%d%d", &n, &w, &h); result = ID =0; while(n--) {scanf("%d%d", &x, &r);if(R *2<= h)Continue;DoubleLen =sqrt(R*r-(h/2.0) * (h/2.0)); Arr[id].left = X-len; Arr[id++].right = x + len; }STD:: Sort (arr, arr + ID, CMP);DoubleFlag =0.0, Flag2 =0.0; for(inti =0; I! = ID; ++i) {if(Arr[i].left <= flag +1e-7) {if(Arr[i].right > Flag2) flag2 = arr[i].right; }Else{flag = Flag2; ++result;if(Flag +1e-7>= W) Break;if(Arr[i].left > Flag +1e-7) Break; I.; } }if(Flag2 +1e-7< W) result =0;Else if(Flag +1e-7< Flag2) ++result;printf("%d\n", result); }return 0;}
NYOJ12 Water Spraying Device (ii) "Greed"