数据太强了导致可以胡搞过这道题
查看原帖
数据太强了导致可以胡搞过这道题
1128559
guoguo160楼主2025/1/24 19:22
#include <bits/stdc++.h>

#define int long long 

#define PII pair<int,int>

using namespace std;

const int N = 400010;

int n;
pair<int, int> a[N];

bool cmp(PII a,PII b) {
    if(a.first*a.second==b.first*b.second) {
        if(a.first==b.first){
            return a.second>b.second;//这个地方胡搞一下
        }
        return a.first>b.first;//这个地方再胡搞一下
    }
    return a.first*a.second<b.first*b.second;
}

inline int dist(int i, int j) {
    return (a[i].first - a[j].first) * (a[i].first - a[j].first) +
        (a[i].second - a[j].second) * (a[i].second - a[j].second);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin >> n;
    for (int i = 1;i <= n;++i) {
        cin >> a[i].first>>a[i].second;
        // swap(a[i].first,a[i].second);
    }
    sort(a + 1, a + n + 1,cmp);
    int MinDist = LLONG_MAX;
    for (int i = 1;i <= n;++i) {
        for (int j = 1;j <= 680 && i + j <= n;++j) {
            MinDist = min(MinDist, dist(i, j+i));
        }
    }
    cout<<MinDist<<"\n";
    return 0;
}
2025/1/24 19:22
加载中...