BZOJ2458 [BeiJing2011] Minimum triangle

Source: Internet
Author: User

Description

Xaviera is now encountering an interesting question.
There are n points on the plane, Xaviera want to find the smallest triangle in the perimeter.
Because of the very many points, the distribution is also very chaotic, so Xaviera want to ask you to solve this problem.
To reduce the difficulty of the problem, the triangles here also include three points of the collinear line.

Input

The first line contains an integer n representing the number of points.
The next n rows have two integers per line, representing the coordinates of the point.

Output

The output has only one row, containing a 6-bit decimal, which is the perimeter of the triangle with the shortest perimeter (rounded).

Sample Input4
1 1
2 3
3 3
3 4

Sample Output3.414214


HINT

100% of the data are n≤200000.

Source

Day1

Positive solution: Divide and conquer the problem report: with the plane nearest point to the practice is the same, but when looking for a more layer for on it. Do not repeat, the code is as follows:
1 //It's made by jump~2#include <iostream>3#include <cstdlib>4#include <cstring>5#include <cstdio>6#include <cmath>7#include <algorithm>8#include <ctime>9#include <vector>Ten#include <queue> One#include <map> A#include <Set> - using namespacestd; -typedefLong LongLL; the Const intMAXN =200011; - #defineRG Register - Const DoubleINF =1e20; - intN; + Doubleans; - structnode{ +     Doublex, y; A }A[MAXN],B[MAXN]; at  -InlineintGetint () - { -Rgintw=0, q=0;CharC=GetChar (); -      while((c<'0'|| C>'9') && c!='-') C=getchar ();if(c=='-') q=1, c=GetChar (); -      while(c>='0'&& c<='9') w=w*Ten+c-'0', C=getchar ();returnQ? -w:w; in } -InlineBOOLCMP (node Q,node QQ) {returnq.x<qq.x;} toInlineBOOLCmpy (node Q,node QQ) {returnq.y<qq.y;} +InlineDouble Get(RGintI,rgintj) {returnsqrt ((a[i].x-a[j].x) * (a[i].x-a[j].x) + (A[I].Y-A[J].Y) * (a[i].y-a[j].y));} -InlineDoubleGETB (RGintI,rgintj) {returnsqrt ((b[i].x-b[j].x) * (b[i].x-b[j].x) + (B[I].Y-B[J].Y) * (b[i].y-b[j].y));} theInlinevoidDiv_solve (intLintR) { *     if(L==R)return;if(L +1==R)return ; $RgintMid= (L+R)/2; Div_solve (L,mid); Div_solve (mid+1, R);Long DoubleDis1,dis2,dis3;Panax NotoginsengRgintCnt=0; b[++cnt]=A[mid]; -      for(RGinti=mid-1; i>=l;i--)if(A[mid].x-a[i].x<=ans) b[++cnt]=a[i];Else  Break; the      for(RGintI=mid+1; i<=r;i++)if(A[i].x-a[mid].x<=ans) b[++cnt]=a[i];Else  Break; +Sort (b +1, b+cnt+1, cmpy); A      for(RGintI=1; i<cnt;i++) the      for(RGintj=i+1; j<cnt;j++) { +         if(Fabs (B[I].Y-B[J].Y) >ans) Break;  -dis1=Getb (i,j); $          for(RGintk=j+1; k<=cnt;k++) { $         if(Fabs (B[I].Y-B[K].Y) >ans) Break; -DIS2=GETB (J,K); dis3=Getb (i,k); -         if(Dis1+dis2+dis3<ans) ans=dis1+dis2+Dis3; the         } -     }Wuyi } the  -InlinevoidWork () { WuN=getint (); for(RGintI=1; i<=n;i++) A[i].x=getint (), a[i].y=getint (); -Sort (A +1, a+n+1, CMP); ans=Get(n2, N-1)+Get(n2, N) +Get(n1, n); AboutDiv_solve (1, n); $printf"%.6LF", ans); - } -  - intMain () A { + Work (); the     return 0; -}

BZOJ2458 [BeiJing2011] Minimum triangle

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.