注意每个圆管辖的区间不是最左或最右的端点而是和被覆盖图形的交点。
直接按照每个圆的left排序
每次尽量寻找靠右的就可以了。
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <cmath>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#define INF 0x3f3f3f3f
using namespace std;
//int n, m,q ;
typedef long long LL;
const double PI = 3.141592653589793;
const double r = 6378 ;
const int maxn = 10000+10;
int n,l,w;
struct Point
{
double pos,r,st,ed;
} s[maxn];
bool cmp(const Point &t1, const Point & t2)
{
return t1.st < t2.st;
}
int main()
{
while(cin >> n >> l >> w)
{
int E = 0;
double a,b;
for(int i = 0 ; i < n ; i++)
{
cin >> a >> b;
if(b*2 > w)
{
s[E].pos = a ;
s[E].r = b;
s[E].st=s[E].pos - sqrt(1.0*b*b-1.0*w*w/4);
s[E].ed = s[E].pos + sqrt(1.0*b*b-1.0*w*w/4);
E++;
}
}
sort(s,s+E,cmp);
if(s[0].st > 0)
{
cout << "-1" << endl;
continue;
}
double up = 0;
double low = 0;
int sum = 0;
while(up < l)
{
double low1;
bool flag = false;
for(int j = 0; j < E ; j++)
{
if(s[j].st <= low && s[j].ed > up)
{
up = s[j].ed;
flag = true;
}
}
if(!flag)
{
sum=-1;
break;
}
low = up;
sum++;
}
cout << sum << endl;
}
return 0;
}