1328:Radar Installation
题目链接http://bailian.openjudge.cn/practice/1328/
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef struct Node {
double l, r;
bool operator<(const Node& a)const {
return l < a.l;
}
}node;
node a[1100];
int n, d;
bool is_can=true;
void hanshu(int x,int y,int index){
if (y > d) {
is_can = 0;
}
else {
double c = sqrt(1.0*(d * d - y * y));
a[index].l = x - c;
a[index].r = x + c;
}
}
int main() {
int ans = 1;
while (cin >> n >> d) {
if (n == 0 && d == 0) {
break;
}
int x, y;
is_can = true;
for (int i = 0; i < n; i++) {
cin >> x >> y;
hanshu(x, y, i);
}
if (!is_can) {
printf("Case %d: %d\n",ans++,-1);
continue;
}
sort(a, a + n);
double r = a[0].r;
int sum = 1;
for (int i = 1; i < n; i++) {
if (a[i].l> r) {
//注意
sum++;
r = a[i].r;
}
else{
r = min(r, a[i].r);//注意
}
}
printf("Case %d: %d\n", ans++, sum);
}
return 0;
}