(贪心咯)
千万记得要double ,否则会错的
C++ 代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn= 50100;
struct node
{
double l, r;
}a[maxn];
int d, n;
bool cmp(node a, node b)
{
return a.r < b.r;
}
int main()
{
scanf("%d%d",&n,&d);
for(int i = 1; i <= n; i ++)
{
double x, y;
scanf("%lf%lf",&x,&y);
if(y > d)
{
printf("-1\n");
return 0;
}
a[i].l = x-sqrt(d*d-y*y);
a[i].r = x+sqrt(d*d-y*y);
}
int num = 1;
sort(a+1,a+1+n,cmp);
double q = a[1].r;
for(int i = 2; i <= n; i ++)
{
if(a[i].l <= q)
continue;
else
{
num ++;
q = a[i].r;
}
}
printf("%d\n",num);
return 0;
}
编码罗志祥可还行