P1429 学习笔记

省流:人类智慧题。

题目传送门

引用 3A17K 大佬说的:

我们充分发扬人类智慧:
将所有点全部绕原点旋转同一个角度,然后按x坐标排序
根据数学直觉,在随机旋转后,答案中的两个点在数组中肯定不会离得太远
所以我们只取每个点向后的5个点来计算答案

甚至你连旋转都不需要。

但是为什么我把 \(ans\) 初始化成 0x3f 就过不了!!!!!!!!!!!!!!!!!!!!!!!!

害得我调了好久。。

code
/**********************************************************
 * Author        : dingziyang888
 * Website       : https://www.luogu.com.cn/problem/
 * Created Time  :
 * FileName      :
 * Warning!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * 1.MLE?
 * 2.array size enough?
 * 3.long long?
 * 4.overflow long long?
 * 5.multiple task cleaned?
 * 6.freopen?
 * 7.TLE?
 * *******************************************************/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#define I using
#define AK namespace
#define IOI std
#define A return
#define C 0
#define Ofile(s) freopen(s".in", "r", stdin), freopen (s".out", "w", stdout)
#define Cfile(s) fclose(stdin), fclose(stdout)
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
I AK IOI;

using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using db = double;
using lb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;

constexpr int mod = 998244353;
constexpr int maxn = 2e5 + 5;

int n;
db ans = 1e9;

struct node{
	db x, y;
} point[maxn];

bool cmp(const node &a, const node &b){
	return (a.x < b.x) || (a.x == b.x && a.y < b.y);
}

db sq(db a){
	return a * a;
}

db dis(node a, node b){
	return sqrt(sq(a.x - b.x) + sq(a.y - b.y));
}

int main() {
	freopen("std.in", "r", stdin);
	freopen("std.out", "w", stdout);
	fast;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> point[i].x >> point[i].y;
	sort (point + 1, point + n + 1, cmp);
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= i + 5; j++){
			if (j > n)
				break;
			ans = min(ans, dis(point[i], point[j]));
		}
	cout << fixed << setprecision(4) << ans;
	A C;
}
posted @ 2026-02-05 21:27  constexpr_ll  阅读(1)  评论(0)    收藏  举报