神犇们帮下我吧
  • 板块题目总版
  • 楼主hhhhhhhhhhg
  • 当前回复7
  • 已保存回复7
  • 发布时间2020/10/7 22:22
  • 上次更新2023/11/5 11:38:23
查看原帖
神犇们帮下我吧
370332
hhhhhhhhhhg楼主2020/10/7 22:22

这个程序为什么洛谷上AC了在其他网站会运行时错误?

#include<bits/stdc++.h>
using namespace std;
const int MAXN=1010;
struct Point{
	double l,r;
}a[MAXN];
bool cmp(Point aa,Point bb){
	return aa.r<bb.r;
}
int main(){
	int n,d,ans=1;
	scanf("%d%d",&n,&d);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if(y>d){
			printf("-1");
			return 0;
		}
		int dis=sqrt(d*d-y*y);
		a[i].l=x-dis;a[i].r=x+dis;
	}
	sort(a+1,a+n+1,cmp);
	double now=a[1].r;
	for(int i=2;i<=n;i++)
		if(now<a[i].l){
			now=a[i].r;
			ans++;
		}
	printf("%d",ans);
	return 0;
}
2020/10/7 22:22
加载中...