题意:在一个平面坐标轴上,第一第二象限为海洋,第三第四象限为陆地,x轴上可以放雷达,已知岛屿的坐标求最少可以放多少个雷达。(雷达扫描范围固定)
题解:以岛屿为中心扫描范围为半径算出于x轴的交点,以靠左边的坐标为基准从小到大排序。设一个标记为第一个岛屿的右边,与之后的对比判断。
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define ll long long
#define maxn 2010
using namespace std;
struct node{
double l,r;
}a[1010];
bool cmp(node a,node b){
if(a.l==b.l){
return a.r>b.r;
}else{
return a.l<b.l;
}
}
int main(){
int n,d,x,y,cas = 1;
while(cin>>n>>d&&(n+d)){
int judge = 1;
for(int i = 0 ; i < n ; i++){
scanf("%d %d",&x,&y);
if(y>d){
judge = 0;
continue;
}
a[i].l = 1.0*x - sqrt(1.0*d*d-1.0*y*y);
a[i].r = 1.0*x + sqrt(1.0*d*d-1.0*y*y);
}
if(!judge){
cout<<"Case "<<cas++<<": -1"<<endl;
continue;
}
sort(a,a+n,cmp);
double mark = a[0].r;
int ans = 0;
for(int i = 1 ; i < n ; i++){
if(a[i].l>mark){
mark = a[i].r;
ans++;
}else if(a[i].r<mark){
mark = a[i].r;
}
}
cout<<"Case "<<cas++<<": "<<++ans<<endl;
}
}