poj 1328

来源:互联网 发布:putty串口发送数据 编辑:程序博客网 时间:2024/06/12 20:37
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;


struct dot
{
int x;
int y;
}abc[10000];


struct rad
{
float left;
float right;
}rads[10000];


int comp(const void* a, const void* b)
{
int aa = (*(rad*)a).right;
int bb = (*(rad*)b).right;
return aa - bb;
}




int main()
{
int num, r;
cin >> num >> r;
bool flag = false;
int count = 0;
int ans[1000];
memset(ans, 0, sizeof(ans));
while (num != 0 || r != 0)
{
flag = false;
count++;
int cir = 0;
for (int i = 0; i < num; i++)
{
dot temp;
cin >> temp.x >> temp.y;
if (temp.y > r||temp.y<0)
flag = true;
abc[i] = temp;
}
if (flag)
{
ans[count] = -1;
}
else
{
for(int i=0;i<num;i++)
{
rads[i].left = abc[i].x - sqrt(r*r*1.0 - abc[i].y*abc[i].y*1.0);
rads[i].right = abc[i].x + sqrt(r*r*1.0 - abc[i].y*abc[i].y*1.0);
}
qsort(rads, num, sizeof(rads[0]), comp);
rad temp = rads[0];
cir++;
float now = rads[0].right;
for (int i = 1; i < num; i++)
{
temp = rads[i];
if (now >= temp.left)
{

continue;
}
else
{
now = temp.right;
cir++;
}
}
ans[count] = cir;
}


cin >> num >> r;
}
for(int i=1;i<=count;i++)
{
cout << "Case " << i << ": " << ans[i] << endl;
}
return 0;


}