1

# poj1328

http://poj.org/problem?id=1328

第二：判断到轴的距离小于雷达范围时注意是平方再比较

第三：注意类型。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef struct node
{
int x;
int y;
double right;
double left;
}node;
int cmp(node a,node b)
{
if (a.right!=b.right)//如果a与b不等，那么按右边从小到大排序
return a.right<b.right;
else//如果a与b相等，那么按左边从大到小排序
return a.left>b.left;
}
int main()
{
int n,d,i,j,sum,ok,total;
double temp;
node a[1005];
total=0;
while(scanf("%d%d",&n,&d)==2&&(n||d))
{
memset(a,0,sizeof(a));
total++;
ok=1;
for (i=0;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
if ((d*d-a[i].y*a[i].y<0)||(d<=0))//坑爹题
ok=0;
else
{
a[i].right=sqrt(d*d-a[i].y*a[i].y)+a[i].x;
a[i].left=a[i].x-sqrt(d*d-a[i].y*a[i].y);
}
}
if (!ok)
{
printf("Case %d: -1\n",total);
continue;
}
sort(a,a+n,cmp);//根据右边从小到大排序9
i=0;
sum=1;
temp=a[0].right;
for (i=1;i<n;i++)
if (a[i].left>temp)
{
temp=a[i].right;
sum++;
}
printf("Case %d: %d\n",total,sum);
}
return 0;
}


11-21 130

03-24 225

05-27 1800

06-29 169

11-27 629

07-13 2025

08-02 128

07-25 150

01-23 28

04-26 1865