关于编译
  • 板块灌水区
  • 楼主MspAInt
  • 当前回复11
  • 已保存回复11
  • 发布时间2022/12/17 20:42
  • 上次更新2023/10/29 10:56:30
查看原帖
关于编译
736801
MspAInt楼主2022/12/17 20:42

rt,下面这份代码sort会导致CE,why?

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
const double eps=0.00001;
struct node{
	double x,y;
}a[N];
int n;
double ans=2e9;
double dis(int q,int p){
	double xx=a[q].x-a[p].x;
	double yy=a[q].y-a[p].y;
	return sqrt(pow(xx,2)+pow(yy,2));
}
bool cmp(int q,int p){
	if(fabs(a[q].x-a[p].x)<=eps)
	return a[q].y<a[p].y;
	return a[q].x<a[p].x;
}
signed main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%lf%lf",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=min(n,i+10);j++)
	ans=min(dis(i,j),ans);
	printf("%.4lf",ans);
    return 0;
}
2022/12/17 20:42
加载中...