vvauted @ 2021-12-14 16:52:02
#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
by Electro_Master @ 2021-12-14 16:53:31
std :: ios :: sync_with_stdio(false);
scanf("%d", &n);
这俩东西不能一起用
by 鏡音リン @ 2021-12-14 16:54:42
你把std :: ios :: sync_with_stdio(false);
删了试试啊
by vvauted @ 2021-12-14 16:55:57
@Electro_Master OK
by Electro_Master @ 2021-12-14 16:56:03
std :: ios :: sync_with_stdio(false);
这东西是关闭 cin
和 sacnf
的同步流,用了它不能再用 scanf()
或 getchar()
一类函数。