HDU3694 Fermat Point in quadrangle (for quadrilateral fee)

Source: Internet
Author: User

Test instructions: Give a four-sided shape, ask a point to the quadrilateral four points distance and the minimum distance and how much.

Analysis: If the convex quadrilateral, Ferma is the diagonal intersection, the distance is the diagonal length.

If it is a concave polygon, the Ferma is the concave point.

#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<cstdlib>#include<queue>#include<stack>#include<map>#include<vector>#include<algorithm>#include<ctime>using namespacestd;#defineEPS 1e-8intFabs (Doubled) {    if(Fabs (d) <eps)return 0; Else returnD>0?1:-1;}structpoint{Doublex, y;} p[Ten],sta[Ten];intoper[8][2]={0,1,0,-1,-1,0,1,0,1,1,1,-1,-1,1,-1,-1},top;DoubleX_multi (Point p1,point p2,point p3) {return(p2.x-p1.x) * (P3.Y-P1.Y)-(p3.x-p1.x) * (p2.y-p1.y);}DoubleDis (Point p1,point p2) {returnsqrt ((p1.x-p2.x) * (p1.x-p2.x) + (P1.Y-P2.Y) * (p1.y-p2.y));}BOOLCMP (point A,point b) {if(Fabs (X_multi (p[0],A,B)) >0)return 1; if(Fabs (X_multi (p[0],A,B)) <0)return 0; if(Fabs (Dis (p[0],a)-dis (p[0],B)) <0)        return 1; return 0;}voidGraham (intN) {    inti,k=0, tot;  for(i=1; i<n;i++)        if((P[I].Y&LT;P[K].Y) | | ((P[I].Y==P[K].Y) && (p[i].x<p[k].x)))  K=i; Swap (p[0],p[k]); Sort (P+1, p+n,cmp); sta[0]=p[0],sta[1]=p[1]; I=top=1;  for(i=2; i<n;i++)    {         while(top>=1&&fabs (X_multi (p[i],sta[top],sta[top-1])) >=0)        {            if(top==0) Break; Top--; } sta[++top]=P[i]; }}intMain () {inti,j;  while(~SCANF ("%LF%LF%LF%LF%LF%LF%LF%LF", &p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y,&p[3].x,&p[3].y)) {if(p[0].x==-1&&p[0].y==-1&&p[1].x==-1&&p[1].y==-1&&p[2].x==-1&&p[2].y==-1&&p[3].x==-1&&p[3].y==-1)             Break; Graham (4); Doubleans; if(top==3) ans=dis (sta[0],sta[2]) +dis (sta[1],sta[3]);//convex quads directly take diagonal intersections        Else{ans=1e50; Doublesum=0;  for(i=0;i<4; i++) {sum=0.0;  for(j=0;j<4; j + +)                    if(i!=j) Sum+=Dis (P[i],p[j]); Ans=min (Sum,ans); }} printf ("%.4lf\n", ans); }    return 0;}

HDU3694 Fermat Point in quadrangle (for quadrilateral fee)

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.