acdream 1414 Geometry Problem

Geometry Problem

Time Limit:  2000/1000MS (Java/Others)  Memory Limit:  128000/64000KB (Java/Others)      Special Judge
Problem 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 x 11, y 11, x 12, y 12— the coordinates of the ends of the first segment. The second line contains x 21. y 21, x 22, y 22 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 10 2 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 10 10 by their absolute values. The jury makes all comparisons of real numbers with the precision of 10 -4.
Sample Input
0 0 0 4
1 0 1 4
0 0 0 0
0 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;
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值