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
-
-
22 8 61 14 52 10 64 56 5
-
-
Sample output
-
Problem-solving ideas: The most important thing is the transformation of ideas, the area cover to transform into a range of coverage on it.
/* For interval coverage: First set a starting point star. Find all the intervals after the start of the sequence that are less than or equal to the star, and find the largest interval of the endpoint as the new starting point for star. Repeat the above operation to get the minimum number of intervals required. */#include <bits/stdc++.h>using namespace std;struct seg{double left,right;} Seg[10100];bool CMP (SEG a,seg b) {if (a.left!=b.left) return a.left<b.left; return a.right>b.right;} int main () {int t,i,j,k,n,w,h,xi,ri,cnt; Double Dx,tmp,star; scanf ("%d", &t); while (t--) {scanf ("%d%d%d", &n,&w,&h); tmp=h*h/4.0; Conversion thinking, the area of the circle to transform into a segment of the interval covering for (i=0;i<n;i++) {scanf ("%d%d", &xi,&ri); dx=ri*ri-tmp; if (dx<0) {i--, n--; Skill continue; } dx=sqrt (DX); SEG[I].LEFT=XI-DX; SEG[I].RIGHT=XI+DX; }//Interval overlay sort (seg,seg+n,cmp); Star=0;cnt=0;k=-1; while (Star<w&&star>=seg[k+1].left) {double maxx=-1; for (i=k+1;i<n&&star>=seg[i].left;i++) { if (maxx<seg[i].right) {maxx=seg[i].right; K=i; }} Star=maxx; cnt++; } if (star<w) cout<<0<<endl; else cout<<cnt<<endl; } return 0;}
Nyoj 12--Water Spraying device two —————— "greedy-interval coverage"