NYOJ 题目12喷水装置(二)

时间:2022-11-15 09:22:32
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
struct Point
{
double x,r,x1,x2;
int visit;
}p[10000];
bool cmp(struct Point a,struct Point b)
{
return a.x1<b.x1||(a.x1==b.x1&&a.x2<b.x2);
}
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
int m;
double len,wid;
cin>>m>>len>>wid;
double x,r;
for(int j=0;j<m;j++)
{
cin>>x>>r;
p[j].x=x;
p[j].r=r;
if(r<=wid/2)
{p[j].visit=0;continue;}
else
{
double d=sqrt(r*r-wid*wid/4);
p[j].x1=x-d;
p[j].x2=x+d;
p[j].visit=1;
} }
sort(p,p+m,cmp);
int a=0,b=0;
int k=0;
for(int j=0;j<m;j++)
{
if(p[j].visit)
{
if(p[j].x1<a)
a=p[j].x1;
if(p[j].x1<=b)
{
b=p[j].x2;
k++;
if(b>=len)
break; }
}
}
if(a<=0&&b>=len)
cout<<k<<endl;
else
cout<<0<<endl; }
return 0; }