Soj-1, 11512

Source: Internet
Author: User
Tags creative commons attribution
11512. Big circle Constraints

Time Limit: 2 secs, memory limit: 256 MB

Description

 

On the opening ceremony of World Cup there was a part where contains kids from around the world was trying to make a big circle on the field which symbolized tolerance and multicultural friendship.

They succeed in making a perfect circle, but as they didn't practice very much, kids weren't uniformly distributed on circle. you spotted that very quickly, and you want to know what is the minimum distance between some two kids.

 

Input

 

First line of the input contains number N (2 <= n <= 10 ^ 5) representing number of kids. each of next n lines contains two real numbers rounded on two decimal places-coordinates of the each kid. all coordinates will be in interval [-10 ^ 6, 10 ^ 6]. it is guaranteed that all points will be on circle.

 

 

Output

 

First and only line of output shoshould contain one real number (rounded on two decimal places)-Euclidian Distance between two nearest kids. euclidian Distance between points (x1, Y1) and (X2, Y2) is SQRT (x1-x2) ^ 2 + (y1-y2) ^ 2 ).

 

Sample Input
51.00 4.00-0.50 -1.604.00 1.003.12 3.12-1.60 -0.50
Sample output
1.56
Hint

 

In the sample, kids at points (−0.50, −1.60) and (−1.60, −0.50) are nearest and distance between them is 1.56.

 

Problem Source

2014/jboi 2014

 

Question: Find the shortest String Length formed by several points on the circle.

Idea: first select three points to determine the center of the center (the vertical line intersection of the two strings), and then translate the entire circle to make the center and the coordinate origin coincide, in this way, we can sort each point counterclockwise from the positive and half axes of the X axis, and then find the length of the string formed by the adjacent two points. The minimum value is the answer.

 

 1 // Problem#: 11512 2 // Submission#: 3027891 3 // The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License 4 // URI: http://creativecommons.org/licenses/by-nc-sa/3.0/ 5 // All Copyright reserved by Informatic Lab of Sun Yat-sen University 6 #include<bits/stdc++.h> 7 using namespace std; 8 typedef long long ll; 9 struct P{10     double x,y;11 };12 vector<P>v;13 int n;14 double X,Y;15 inline double d2(P a,P b)16 {17     return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);18 }19 int F(P p)20 {21     if(p.y == 0)return p.x > 0 ? 0 : 4;22     if(p.x == 0)return p.y > 0 ? 2 : 6;23     if(p.x > 0 && p.y > 0)return 1;24     if(p.x < 0 && p.y > 0)return 3;25     if(p.x < 0 && p.y < 0)return 5;26     if(p.x > 0 && p.y < 0)return 7;27 }28 bool cmp(const P& a,const P& b)29 {30     int fa = F(a),fb = F(b);31     if(fa != fb)return fa < fb;32     else return a.y * b.x < a.x * b.y;33 }34 int main()35 {36     int i;37     while(~scanf("%d",&n))38     {39         v.clear();40         for(i=0;i<n;i++)41         {42             P p;43             scanf("%lf%lf",&p.x,&p.y);44             v.push_back(p);45         }46         if(n==2)47         {48             printf("%.2f\n",sqrt(d2(v[0],v[1])));49             continue;50         }51         double xm01=(v[0].x+v[1].x)/2.0,ym01=(v[0].y+v[1].y)/2.0;52         double xm12=(v[1].x+v[2].x)/2.0,ym12=(v[1].y+v[2].y)/2.0;53         double dym01m12 = ym12 - ym01;54         double dx01=v[1].x-v[0].x,dy01=v[1].y-v[0].y;55         double dx12=v[2].x-v[1].x,dy12=v[2].y-v[1].y;56         X = (dym01m12 * dy12 * dy01 - xm01 * dx01 * dy12 + xm12 * dx12 * dy01) / (dx12 * dy01 - dx01 * dy12);57         if(dy01)58         Y = ym01 - (X - xm01) * dx01 / dy01;59         else//dy12 != 060         Y = ym12 - (X - xm12) * dx12 / dy12;61         for(i=0;i<n;i++)62         {63             v[i].x-=X;64             v[i].y-=Y;65         }66         sort(v.begin(),v.end(),cmp);67         double ans=d2(v[0],v[1]);68         double d;69         for(i=1;i<n;i++)ans = min(ans,d=d2(v[i-1],v[i]));70         ans = min(ans,d2(v[n-1],v[0]));71         printf("%.2f\n",sqrt(ans));72     }73     return 0;74 }75 /*76 377 0.71 0.7178 0.71 -0.7179 -1.00 0.0080 */                                 

 

PS: The data of the original question seems to be not strong enough. The above group of data cannot be accessed even if 70th lines of code are removed.

Soj-1, 11512

Related Article

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.