For each island, a radar is required in the range [a, B] to sort the left coordinates of these ranges.
The right coordinate of the first Island is right,
The initial radar count is 1. For the second island, if its right coordinate is smaller than that of the right coordinate, it indicates that range 2 contains range 1, and the radar count does not need to be increased, and set right = the right coordinate of Island 2;
If its right coordinate is greater than right, and the left coordinate of Island 2 is greater than right, the number of radars is + 1, and the right coordinate is set to Island 2.
# Include <algorithm> # include <math. h> # include <iostream> Using Namespace STD; typedef Struct Island { Double L; Double R;} node;IntQcmp (ConstVoid* Arg1,ConstVoid* Arg2 ){Return(Node *) arg1)-> L> (node *) arg2)-> L )? 1:-1 ;} Int CMP (node arg1, node arg2 ){ Return Arg1.l <arg2.l ;} Int Main ( Int Argc, Char * Argv []) { // Freopen ("D:/t.txt", "r", stdin ); Int Count;Int R; Int C = 0; While (CIN> count> r & (count | r )){ Bool Err = False ; Node N [1000]; C ++; For ( Int I = 0; I <count; I ++ ){ Double X, Y; CIN> x> Y; y = Y <0? -Y: Y; If (Y> r) {err = True ;} Double D = SQRT (R * r-y * Y); N [I]. L = x-D; n [I]. r = x + D ;}If (ERR) {printf (" Case % d:-1 \ n ", C ); Continue ;} Qsort (n, count,Sizeof(N [0]), qcmp ); // Sort (N, N + count, CMP ); Int Ans = 1; Double Left = N [0]. R; For ( Int J = 1; j <count; j ++ ){ If(N [J]. r <= left) {left = N [J]. R ;}Else{If(N [J]. L> left) {ans ++; left = N [J]. r ;}} } Printf ("Case % d: % d \ n ", C, ANS );} Return 0 ;}