连样例都过不了的代码AC了

P7883 平面最近点对(加强加强版)

![](//xn--9zr.tk/jk)
by Leap_Frog @ 2021-10-18 21:34:06


~~平面最近点对加强加强版的加强版~~
by Carnival @ 2021-10-18 21:35:25


``` return 1.0 / 0.0; ``` 这不是无穷大吗?
by cancan123456 @ 2021-10-18 21:35:38


样例 1 输出了 200000000000000.
by cancan123456 @ 2021-10-18 21:36:32


看走眼了,dbq
by Leap_Frog @ 2021-10-18 21:37:02


orz
by bigju @ 2021-10-18 21:38:16


~~除数为0不会RE吗~~
by ScottSuperb @ 2021-10-18 21:58:26


我的情况跟你一样。。 [关于 EVOI Round 2 C题 的疑惑](https://www.luogu.com.cn/discuss/367230)
by 大K @ 2021-10-18 21:58:40


你说得对,样例加进数据了。 不过其实本来也只是挂了一个小边界?
by fstqwq @ 2021-10-24 18:10:46


我找到问题了,确实是边界挂了,这么写就对了: ```cpp #include <cstdio> #include <cmath> #include <algorithm> using namespace std; struct Point { double x, y; } point[400005]; bool operator < (const Point & a, const Point & b) { return a.x == b.x ? a.y < b.y : a.x < b.x; } bool cmpy(const int & a, const int & b) { return point[a].y < point[b].y; } double inline dist(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } double inline dist(int i, int j) { return dist(point[i].x, point[i].y, point[j].x, point[j].y); } double inline min(double a, double b) { return a < b ? a : b; } int temp[400005]; double calc(int l, int r) { if (l == r - 1) { return 1.0 / 0.0; } double d = 1.0 / 0.0; int mid = (l + r) / 2; d = min(d, min(calc(l, mid), calc(mid, r))); int len = 0; for (int i = l; i < r; i++) { if (fabs(point[i].x - point[mid].x) < d) { temp[len ++] = i; } } sort(temp, temp + len, cmpy); for (int i = 0; i < len; i++) { for (int j = i + 1; j < len && point[temp[j]].y - point[temp[i]].y < d; j++) { d = min(d, dist(temp[i], temp[j])); } } return d; } int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%lf %lf", &point[i].x, &point[i].y); } sort(point, point + n); double ans = calc(0, n); printf("%.0lf", ans * ans); return 0; } ```
by cancan123456 @ 2021-11-15 20:45:56


| 下一页