The closest point on the P1257 plane is close to the P1257 plane.

Source: Internet
Author: User

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 }

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.