acdream 1414 Geometry Problem,acdreamgeometry

來源:互聯網
上載者:User

acdream 1414 Geometry Problem,acdreamgeometry

Geometry ProblemTime Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)     Special JudgeSubmitStatusProblem Description      Peter is studying in the third grade of elementary school. His teacher of geometry often gives him difficult home tasks.
      At the last lesson the students were studying circles. They learned how to draw circles with compasses. Peter has completed most of his homework and now he needs to solve the following problem. He is given two segments. He needs to draw a circle which intersects interior of each segment exactly once.
      The circle must intersect the interior of each segment, just touching or passing through the end of the segment is not satisfactory.
      Help Peter to complete his homework.
 Input      The input file contains several test cases. Each test case consists of two lines.
      The first line of the test case contains four integer numbers x11, y11, x12, y12— the coordinates of the ends of the first segment. The second line contains x21. y21, x22, y22 and describes the second segment in the same way.
      Input is followed by two lines each of which contains four zeroes these lines must not be processed.
      All coordinates do not exceed 102 by absolute value.Output      For each test case output three real numbers — the coordinates of the center and the radius of the circle. All numbers in the output file must not exceed 1010 by their absolute values. The jury makes all comparisons of real numbers with the precision of 10-4.Sample Input
0 0 0 41 0 1 40 0 0 00 0 0 0
Sample Output
0.5 0 2
Hint


題解及代碼:

      這道題目的做法 應該挺多的吧,我的解法不知道是不是對的,但是能AC(個人認為是對的)。

     首先我們從兩條直線各取一個點,要求:兩點的距離最短,之後我們把這兩個點的中點作為圓的圓心,把圓心到兩點的距離求出來記為r,然後求出圓心到另外兩直線端點的距離r1,r2,半徑R=(r+min(r1,r2))/2.0,就行了。


代碼:

#include <iostream>#include <cstdio>#include <cmath>using namespace std;struct Point{    double x,y;    Point(){}    Point(double X,double Y):x(X),y(Y) {}}t;struct Line{    Point l,r;}a,b;double dis(Point a,Point b){    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}void init(){    double Dis[5];    Dis[1]=dis(a.l,b.l);    Dis[2]=dis(a.l,b.r);    Dis[3]=dis(a.r,b.l);    Dis[4]=dis(a.r,b.r);    int p=1;    for(int i=2;i<=4;i++)    {        if(Dis[i]<Dis[p]) p=i;    }    if(p==2)    {        t=b.r;b.r=b.l;b.l=t;    }    if(p==3)    {        t=a.l;a.l=a.r;a.r=t;    }    if(p==4)    {        t=a.l;a.l=a.r;a.r=t;        t=b.r;b.r=b.l;b.l=t;    }}int main(){    while(scanf("%lf%lf%lf%lf",&a.l.x,&a.l.y,&a.r.x,&a.r.y))    {        scanf("%lf%lf%lf%lf",&b.l.x,&b.l.y,&b.r.x,&b.r.y);        if(!a.l.x&&!a.l.y&&!a.r.x&&!a.r.y&&!b.l.x&&!b.l.y&&!b.r.x&&!b.r.y)            break;        init();        double x,y,r;        x=(a.l.x+b.l.x)/2.0;        y=(a.l.y+b.l.y)/2.0;        r=dis(Point(x,y),a.l);        double r1,r2;        r1=dis(Point(x,y),a.r);        r2=dis(Point(x,y),b.r);        r=r+min(r1,r2);        r/=2.0;        printf("%.5lf %.5lf %.5lf\n",x,y,r);    }    return 0;}










聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.