Ä£° Ç çó Ë ä± ß Î % ***********************************************************

Source: Internet
Author: User

Ä£° Ç çó Ë ä± ß Î % ***********************************************************
Fermat Point in QuadrangleTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 2039 Accepted Submission (s): 375


Problem DescriptionIn geometry the Fermat point of a triangle, also called Torricelli point, is a point such that the total distance from the three vertices of the triangle to the point is the minimum. it is so named because this problem is first raised by Fermat in a private letter. in the following picture, P0 is the Fermat point. you may have already known the property that:


Alice and Bob are learning geometry. Recently they are studying about the Fermat Point.

Alice: I wonder whether there is a similar point for quadrangle.

Bob: I think there must exist one.

Alice: Then how to know where it is? How to prove?

Bob: I don't need to Wait t know. Wait beyond the point may hold the similar property as the case in triangle.

Alice: It sounds reasonable. Why not use our computer to solve the problem? Find the Fermat point, and then verify your assumption.

Bob: A good idea.

So they ask you, the best programmer, to solve it. find the Fermat point fZ compiler · plugin "http://www.bkjia.com/kf/ware/vc/" target = "_ blank" class = "keylink"> Platform + cjxicj4kedxzdiffusion + Platform + PGJyPgo8YnI + response + IKHcIDEwMDAgKGkgPSAxLCChrSwgNCkuPGJyPgo8YnI + clrozsbpbnb1dcbpcyblbmrlzcbiesblwdodcatms4kiao8yni + response = "brush: java; "> 0 0 1 1 1 0 0 11 1 1 1 1 1 1 1-1-1-1-1-1-1-1-1
Sample Output
2.82840.0000
///·ÑÂíµã#include
  
   #include
   
    #include
    
     const double esp=1e-8;struct point{    double x,y;} a[10];struct line{    double a,b,c;};double min(double a,double b){    return a
     
      0)?1:-1;}double cross(point a, point b, point c){    return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);}void lineintersect(line l1,line l2, double &x, double &y){    double d=l1.a*l2.b-l2.a*l1.b;    x=(l2.c*l1.b-l1.c*l2.b)/d;    y=(l2.a*l1.c-l1.a*l2.c)/d;}void lineform(double x1,double y1,double x2,double y2, line &temp)//ax+by+c=0;{    temp.a=y2-y1;    temp.b=x1-x2;    temp.c=x2*y1-x1*y2;}double dit[5];int main(){    int i,j;    double ans;    point fermat;    while(1)    {        bool flag=false;        for(i=1; i<=4; i++)        {            scanf("%lf%lf",&a[i].x,&a[i].y);            if(a[i].x!=-1||a[i].y!=-1)                flag=true;        }        if(!flag)            break;        memset(dit,0,sizeof(dit));        for(i=1; i<=4; i++)        {            for(j=1; j<=4; j++)            {                dit[i]+=dis(a[i],a[j]);            }        }        line temp1,temp2;        double fx,fy;        if(cross(a[1],a[2],a[3])*cross(a[1],a[2],a[4])<0)        {            lineform(a[1].x,a[1].y,a[2].x,a[2].y,temp1);            lineform(a[3].x,a[3].y,a[4].x,a[4].y,temp2);            lineintersect(temp1,temp2,fx,fy);        }        else if(cross(a[1],a[3],a[4])*cross(a[1],a[3],a[2])<0)        {            lineform(a[1].x,a[1].y,a[3].x,a[3].y,temp1);            lineform(a[2].x,a[2].y,a[4].x,a[4].y,temp2);            lineintersect(temp1,temp2,fx,fy);        }        else if(cross(a[1],a[4],a[3])*cross(a[1],a[4],a[2])<0)        {            lineform(a[1].x,a[1].y,a[4].x,a[4].y,temp1);            lineform(a[2].x,a[2].y,a[3].x,a[3].y,temp2);            lineintersect(temp1,temp2,fx,fy);        }        ans=0;        fermat.x=fx;        fermat.y=fy;        for(i=1; i<=4; i++)        {            ans+=dis(fermat,a[i]);        }        double tans=min(min(dit[1],dit[2]),min(dit[3],dit[4]));        double ret=min(tans,ans);        printf("%.4lf\n",ret);    }    return 0;}
     
    
   
  


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.