The closest point on the P1257 plane is close to the P1257 plane.
Description
Given n points on the plane, find the distance between a pair of points, so that the distance is the smallest among all the points of the n points.
Input/Output Format
Input Format:
Row 1: n; 2 ≤ n ≤ 200000
Next n rows: each row has two real numbers: x y, which indicate the row coordinates and column coordinates of a point, separated by a space in the middle.
Output Format:
Only one row, a real number, indicates the shortest distance, accurate to four digits after the decimal point.
Input and Output sample
Input example #1:
31 11 22 2
Output sample #1:
1.0000
Description
0 <= x, y <= 10 ^ 9
Violent water...
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<cstdlib> 6 using namespace std; 7 const int MAXN=10001; 8 void read(int & n) 9 {10 char c='+';int x=0;11 while(c<'0'||c>'9')c=getchar();12 while(c>='0'&&c<='9')13 {14 x=x*10+(c-48);15 c=getchar();16 }17 n=x;18 }19 int n;20 struct node21 {22 int x;23 int y;24 }a[MAXN];25 double ans=12700000;26 int main()27 {28 read(n);29 for(int i=1;i<=n;i++)30 {31 read(a[i].x);32 read(a[i].y);33 }34 for(int i=1;i<=n;i++)35 {36 for(int j=i+1;j<=n;j++)37 {38 double p=sqrt((fabs(a[j].x-a[i].x)*fabs(a[j].x-a[i].x))+(fabs(a[j].y-a[i].y)*fabs(a[j].y-a[i].y)));39 if(p<ans)40 ans=p;41 }42 }43 printf("%.4lf",ans);44 return 0;45 }