可能测试数据错了
查看原帖
可能测试数据错了
1482247
cjspengyu楼主2024/11/5 11:45

因为担心使用sqrt函数带来的精度误差,我都用的int来计算。贪心的思路应该没错,但是分数是100/110100/110,最后一个测试点错了。合理怀疑可能是测试数据有误。

代码如下

#include<bits/stdc++.h>
using namespace std;
int n,d,dd,cnt,r,f=1;
struct zb{
	int x,y,l,r,c;
	void set(){
		int jd=dd-this->y*this->y;
		this->c=0;
		while(jd>=0 && this->c*this->c<=jd)	this->c++;
		this->c--;
		this->l=this->x-c,this->r=this->x+c;
	}
}a[1005];
bool operator<(zb x,zb y){
	if(x.c<0)	return true;
	if(x.r-y.r)	return x.r<y.r;
	return x.l<y.l;
}
int main(){
	cin>>n>>d,dd=d*d;
	for(int i=1; i<=n; i++)	cin>>a[i].x>>a[i].y,a[i].set();
	sort(a+1,a+n+1);
	for(int i=1; i<=n; i++){
		if(a[i].c<0)		cnt=-1,i=n+1;
		else if(f)		f=0,r=a[i].r,cnt++;
		else if(r<a[i].l)	r=a[i].r,cnt++;
	}
	cout<<cnt;
	return 0;
} 

望各位大神提供意见,不胜感激

2024/11/5 11:45
加载中...