AcWing 112. 雷达设备
原题链接
中等
作者:
KUN_
,
2019-04-05 21:41:30
,
所有人可见
,
阅读 804
C++ 代码
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1010;
const double inf = 0x3f3f3f3f;
const double esp = 1e-6;
struct node{
double l, r;
bool operator < (const node & a) const{
return l < a.l;
}
}p[N];
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
#endif //ONLINE_JUDGE
int n, iCase = 1;
double d, x, y;
while(scanf("%d%lf", &n, &d)){
bool flag = false;
if(n == 0 && d == 0) break;
for(int i = 0; i < n; i++){
scanf("%lf%lf", &x, &y);
if(y > d) flag = true;
double len = sqrt(d * d - y * y);
p[i] = (node){x - len, x + len};
}
printf("Case %d: ", iCase++);
if(flag) printf("-1\n");
else{
int ans = 0;
sort(p, p + n);
double pos = - inf;
for(int i = 0; i < n; i++){
if(p[i].l > pos + esp){
pos = p[i].r + esp;
ans++;
}
else{
pos = min(pos, p[i].r);
}
}
printf("%d\n", ans);
}
}
return 0;
}
else{
pos = min(pos, p[i].r);
}
请问这个是为了干啥?
在区间上的某一个点安装一个,得先保证前面所有的满足,所以需要取一个最小值