Vongang original. If any error occurs, please correct it. Reprinted Please note: http://www.cnblogs.com/vongang/
First, find the radar range corresponding to each Island, and then use greedy ideas. Class is a problem of venue layout. (Note: The C-language qsort function may have some errors in floating-point operations. I have contributed countless wa ...)
# Include <stdio. h>
# Include <stdlib. h>
# Include <math. h>
# Define n 1002
Struct Node
{
Double S;
Double E;
} Num [N];
Int CMP (const void * a, const void * B)
{
Return (* (struct node *) a). S> = (* (struct node *) B). S? 1:-1; // special note !!!
}
Int main ()
{
// Freopen ("data. In", "r", stdin );
Int N, I, CAS = 0;
Int X, Y, R;
While (scanf ("% d", & N, & R )! = EOF)
{
If (n = 0 & R = 0) break;
Int flag = 0;
For (I = 0; I <n; I ++)
{
Scanf ("% d", & X, & Y );
If (Y> r | Y <0) Flag = 1;
Else
{
Num [I]. S = x-SQRT (double) (R * r-y * y ));
Num [I]. E = x + SQRT (double) (R * r-y * y ));
}
}
If (r <0 | flag) {printf ("case % d:-1 \ n", ++ CAS); continue ;}
Qsort (Num, N, sizeof (struct node), CMP );
Double TMP = num [0]. E;
Int COUNT = 1;
For (I = 1; I <n; I ++)
{
If (TMP <num [I]. s)
{
Count ++;
TMP = num [I]. E;
}
Else
{
If (TMP> num [I]. e) TMP = num [I]. E;
}
}
Printf ("case % d: % d \ n", ++ cas, count );
}
Return 0;
}