The topic describes a lawn, transverse long w, longitudinal length of H, in its horizontal to the centerline of the center line is equipped 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 the circle. Please select as few water spray devices as possible in the given sprinkler system to moisten the entire lawn. Enter the first line to enter 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 a positive integer for each set of test data, indicating how many water jets are required, each with a single line of output.
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
12
1#include <stdio.h>2#include <math.h>3 4 intMainintargcConst Char*argv[]) {5 intm, N;6 intW, H;7 float from[10001], to[10001];8scanf"%d", &m);9 while(m--) {Tenscanf" %d%d%d", &n, &w, &h); One intK =1; A floatX, r, t = h *1.0/2, sq; - for(inti =0; I < n; i++) { -scanf"%f%f", &x, &R); theSq = sqrt (R * r-t *t); - if(R >t) { - from[K] = x-sq; -to[k++] = x +sq; + } - } + //sort first keyword from secondary keyword to A for(inti =1; I < K-1; i++) { at for(intj = i +1; J < K; J + +) { - if( from[I] > from[J] | | ( from[I] = = from[j] && To[i] <To[j])) { - floattemp = from[i]; - from[I] = from[j]; - from[j] =temp; -temp =To[i]; inTo[i] =To[j]; -TO[J] =temp; to } + } - } the //determine if the interval header is covered * if( from[1] >0) { $printf"0\n");Panax Notoginseng Continue; - } the intAns =1; + floatFLAGT = to[1], flag = to[1]; A from[K] =W; the for(inti =2; I < K; i++) { + if( from[i] <= flagt && to[i] > Flagt && to[i] > flag) {//find a relatively large interval -Flag =To[i]; $ } $ if( from[i +1] >flagt) { -FLAGT =Flag; -ans++; the } - }Wuyi if(Flagt < W) {//determine if the interval tail is covered theprintf"0\n"); - } Wu Else { -printf"%d\n", ans); About } $ } - return 0; -}
View Code
Question B: Water spray Device (ii) (Error in C + +, AC is submitted)