WA了一个晚上,然后是发现栈没清空
,一直以为是精度问题
。
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
struct thing
{
double left,right;
} point[10002];
bool camp(thing a,thing b)
{
if(abs(a.right-b.right) <= 0.0001) return a.left < b.left;
return a.right < b.right;
}
int n,q[10002];
double l,w,p[10002],r[10002];
int main()
{
cin.sync_with_stdio(false);
while(cin>>n>>l>>w)
{
int tot = 0,ans = 1;
memset(q,0,sizeof(q));
for(int i = 1;i <= n;i++)
{
cin>>p[i]>>r[i];
if(2.0*r[i] <= w) continue;
double d = sqrt(r[i]*r[i] - w*w/4.0);
point[++tot].left = max(0.0,p[i]-d);
point[tot].right = p[i]+d;
}
sort(point+1,point+1+tot,camp);
int t = 0;
for(int i = 1;i <= tot;i++)
{
while(t && point[q[t]].left >= point[i].left) t--;
q[++t] = i;
}
int now = q[1];
if(point[now].left > 0.0)
{
cout<<-1<<endl;
continue;
}
for(int i = 2;i <= t;i++)
{
if(point[now].right < point[q[i]].left) break;
if(point[now].right >= l) break;
if(point[now].right < point[q[i+1]].left || i == t)
{
ans++;
now = q[i];
}
}
if(point[now].right < l)
{
cout<<-1<<endl;
continue;
}
cout<<ans<<endl;
}
}