//404k 79ms
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
typedef
struct tagLINE{
double
left;
double
right;
}Line;
void
sortLineBuf(Line *p, int
num)
{
Line temp;
for
( int i=0; i<num; ++i)
{
for
( int j=i+1; j<num; ++j)
{
if
(p[j].left < p[i].left){
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
}
int
main()
{
int
caseNum = 0;
double
tempPoint;
Line tempLine;
while
( true )
{
int
islandNum = 0, r = 0;
scanf ( "%d%d" , &islandNum, &r);
if
(islandNum == 0 && r == 0) break ;
double
*p = ( double *) malloc ( sizeof ( double ) * islandNum * 2);
double
*pX = p;
double
*pY = p+islandNum;
for ( int
i=0; i<islandNum; ++i){
scanf ( "%lf%lf" , &pX[i], &pY[i]);
}
//
int
rapar = 0;
bool
bImpossible = true ;
Line* pLine = (Line*) malloc ( sizeof (Line) * islandNum);
//1 转换为直线
for ( int
i=0; i<islandNum; ++i){
if
( fabs (pY[i]) > r){
bImpossible = false ;
rapar = -1;
break ;
}
tempPoint = sqrt (r*r - pY[i]*pY[i]);
pLine[i].left = pX[i]-tempPoint;
pLine[i].right = pX[i]+tempPoint;
}
if
(bImpossible)
{
rapar = 1;
//2
sortLineBuf(pLine, islandNum);
//3 求解线段交集
tempLine = pLine[0];
for
( int i=1; i<islandNum; ++i)
{
if
(pLine[i].left > tempLine.right)
{
++rapar;
tempLine = pLine[i];
}
else
if (pLine[i].right < tempLine.right)
{
tempLine = pLine[i];
}
}
}
printf ( "Case %d: %d\n" , ++caseNum, rapar);
free (p);
free (pLine);
}
return
0;
}
|