思路:
贪心
坐标范围可以用勾股来确定
-1的判断就看纵坐标是否大于半径即可
C o d e Code Code:
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
#define rr register
using namespace std;
int n, d, ans = 1,x[1001],y[1001];
struct node {double l,r;}e[10005];
bool cmp (node xx,node yy){xx.r < yy.r;}//排序
int main ()
{
scanf ("%d%d", &n, &d);
for (rr int i = 1; i <= n; ++i)
{
scanf("%d%d",&x[i],&y[i]);
if (abs(y[i]) > d){printf("-1");return 0;}
e[i].l = (double)x[i] - (double) sqrt(d * d - y[i] * y[i]);//勾股确定范围
e[i].r = (double)x[i] + (double) sqrt(d * d - y[i] * y[i]);
}
sort(e + 1 , e + 1 + n , cmp);
double now = e[1].r;
for(rr int i = 2; i <= n; ++i)
{
if(e[i].l <= now && now <= e[i].r) continue;//贪心找最优解
else {ans++; now = e[i].r;}
}
printf("%d", ans);
return 0;
}