这个题的贪心的方法就是一开始把所有点能够覆盖的范围,按照左边从小打到排序,然后就可以不断更新右边最大,如果一个点的左范围小于有点最大,但是右范围大于右边最大,那么就需要更新右边最大了,然后就这样不断更新就可以。最后有一个就是,从这个0到L 最后一个点的左范围不能超出L
如果找不到一个点来更新右边最大的时候,就可以说无法覆盖输出-1
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
#include <stack>
#include <utility>
#include <string>
#include <sstream>
#include <cstdlib>
#define LL long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 100000 + 10;
int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
double l,w;
int n;
struct P
{
double l,r;
} pt[maxn];
bool cmp(P a,P b)
{
return a.l < b.l;
}
int main()
{
while(scanf("%d%lf%lf",&n,&l,&w) != EOF)
{
int num = 0;
double h = w / 2.0;
for(int i = 0; i < n; i++)
{
double a,b;
cin>>a>>b;
double t = sqrt(b*b - (h*h));
pt[i].l = a - t;
pt[i].r = a + t;
}
sort(pt,pt + n,cmp);
double R = l;
double L = 0;
int ans = 0;
int flag = 0;
double maxr;
while(L<R)
{
maxr=0;
for(int i=0; i<n; i++)
if( pt[i].l-L < 1e-9 && maxr - pt[i].r <1e-9 )
maxr = pt[i].r;
if(fabs(maxr-L)<1e-9)
{
flag = 1;
break;
}
ans++;
L=maxr;
}
if(flag == 1)
printf("-1\n");
else
printf("%d\n",ans);
}
return 0;
}