原题链接:https://www.luogu.com.cn/problem/P1257
算法标签:暴力
涉及知识点:int 数值范围,约为2e9;long long 数值范围,约为9e18
代码:
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxN = 1e4+9;
struct node{
ll x;
ll y;
}que[maxN];
int n;
ll dis(node p1, node p2){
return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
}
int main(){
cin >> n;
for( int i=0; i<n; i++ ){
cin >> que[i].x >> que[i].y;
}
ll ans = 2e18+1;
for( int i=0; i<n; i++ ){
for( int j=i+1; j<n; j++ ){
ll tmp = dis(que[i], que[j]);
if(tmp < ans){
ans = tmp;
}
}
}
printf("%.4f", sqrt(ans));
return 0;
}