Acdrea.1414 geometry problem

Source: Internet
Author: User

Geometry problem Time limit:2000/1000 ms (Java/Others) Memory limit:128000/64000 KB (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


Question and code:

There should be a lot of practices for this question. I don't know if this solution is correct, but it can be AC (I personally think it is correct ).

First, we take a point from two straight lines, which requires that the distance between two points is the shortest. Then we take the midpoint of these two points as the center of the circle, and calculate the distance from the center to the two points as R, then, obtain the distance from the center of the center to the endpoints of the other two straight lines: R1, R2, radius r = (R + min (R1, R2)/2.0.


Code:

#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;}







Acdrea.1414 geometry problem

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.