本地与线上输出不同,求助
查看原帖
本地与线上输出不同,求助
486187
vvautedSN第一魔怔人楼主2021/12/14 16:52
#include <stdio.h>
#include <iomanip>
#include <algorithm>
#include <math.h>
#include <iostream>
#define Maxn 1000005
#define D double

const long long inf = 5e18;
int n;

D min(D a, D b) {
	return a < b ? a : b;
}

struct node {
	D x, y;
	
	friend bool operator < (node a, node b) {
		if(a.x != b.x) return a.x < b.x;
		else if(a.y != b.y) return a.y < b.y; 
		return 0;
	}
}g[Maxn];
 
D p(D a) { return a * a; }
D ab(D a) { return a > 0 ? a : -a; } 
 
D dist(int a, int b) {
	return sqrt(p(ab(g[a].x - g[b].x)) + p(ab(g[a].y - g[b].y)));
} 
 
D Get(int L, int R) {
	if(L == R) return inf;
	int mid = L + R >> 1;
	D d = min(Get(L, mid), Get(mid + 1, R)); 

	for(int i = L; i <= mid; ++ i) {
		for(int j = mid + 1; j <= R; ++ j) {
			if(ab(g[i].x - g[j].x) >= d) break;
			d = min(d, dist(i, j)); 
		}
	}
	
	return d;
} 
 
int main() {
	std :: ios :: sync_with_stdio(false); scanf("%d", &n);
	for(int i = 1; i <= n; ++ i) std :: cin >> g[i].x >> g[i].y;
	std :: sort(g + 1, g + n + 1), std :: cout << std :: setiosflags(std :: ios :: fixed) << std :: setprecision(4) << Get(1, n); 
}

下载的数据本地 AC,提交输出 0

2021/12/14 16:52
加载中...