#include <cstdio>
#include <algorithm>
#include <cmath>
#define MAX_N 1100
using namespace std;
pair<int,int> point[MAX_N];
pair<double,double> arr[MAX_N];
//input
int n,d;
//answer
int ans;
int cnt = 1;
void solve(){
ans = 1;
//对点按左端点进行整理
sort(arr,arr + n);
//for(int i = 0;i < n;i++){
// printf("%lf %lf",arr[i].first,arr[i].second);
// }
double spos = arr[0].second; //最左点的最右距离
for(int i = 1;i < n; i++){
if (arr[i].first - spos > 1e-5) {
ans++;
spos = arr[i].second;
}else{
if (arr[i].second - spos < 1e-5) //下个岛屿的最右坐标小于当前最右可被侦测坐标
{
spos= arr[i].second;
}
}
}
}
int main(){
//freopen("C:\in.txt","r",stdin);
while(scanf("%d%d",&n,&d) != EOF){
int ok = 1;
if(!n && !d)
break;
for(int i = 0;i < n;i++){
scanf("%d%d",&point[i].first,&point[i].second);
if(point[i].second > d) ok = 0;
}
//如果只有一个点
// if(n == 1) {printf("Case %d: 1\n",cnt++); continue;}
//将坐标系上的点转为x轴上的区间
for(int i = 0;i < n;i++){
double x = point[i].first,y = point[i].second;
double len = sqrt((double)(d*d - y*y));
arr[i].first = x - len;
arr[i].second = x + len;
}
if(ok == 0){
printf("Case %d: -1\n",cnt++);
continue;
}else{
solve();
printf("Case %d: %d\n",cnt++,ans);
}
}
return 0;
}
poj 1328 Radar Installation
最新推荐文章于 2021-01-30 22:57:57 发布