| 比赛 |
?板子大赛 |
评测结果 |
WWWWWW |
| 题目名称 |
喷水装置 |
最终得分 |
0 |
| 用户昵称 |
rzzakioi |
运行时间 |
0.087 s |
| 代码语言 |
C++ |
内存使用 |
2.19 MiB |
| 提交时间 |
2026-01-17 10:13:51 |
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int t,n;
double l,w;
struct node{
double l,r;
}a[15005];
bool operator <(const node &x,const node &y){
if(x.l==y.l)return x.r>y.r;
return x.l<y.l;
}
int main(){
freopen("sprinkler.in","r",stdin);
freopen("sprinkler.out","w",stdout);
scanf("%d",&t);
while(t--){
scanf("%d%lf%lf",&n,&l,&w);
bool can=1;
w/=2.0;
for(int i=1;i<=n;i++){
double x,r;
scanf("%lf%lf",&x,&r);
if(r*r-w*w<0)can=0;
if(can){
double dis=sqrt(r*r-w*w);
a[i].l=x-dis;
a[i].r=x+dis;
}
}
if(!can){
printf("-1\n");
continue;
}
sort(a+1,a+n+1);
double now=0,nxt=0;
int ans=1;
for(int i=1;i<=n;i++){
if(a[i].l<=now){
nxt=max(nxt,a[i].r);
}
else{
ans++;
now=nxt;
if(a[i].l>now)can=0;
else nxt=max(nxt,a[i].r);
}
}
if(!can||nxt<l){
printf("-1\n");
}
else{
printf("%d\n",ans);
}
}
return 0;
}