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







《问题解决的艺术:几何学PDF》是一本关于几何学问题解决的书籍。几何学是数学的一个分支,研究空间和图形的属性和关系。这本书旨在帮助读者学习如何解决几何学问题,提供了一些应用数学方法的示例。 《问题解决的艺术:几何学PDF》的内容涵盖了几何学的基本概念和定理,如角度、线段、圆和三角形等。它还介绍了一些常见的几何学问题类型,如证明问题、相似和全等三角形以及平行线关系等。通过这些问题和示例,读者可以学习到如何将几何学概念应用到实际问题中。 这本书的一个重要方面是它教授读者如何运用创造性思维和逻辑推理来解决几何学问题。通过分析和研究问题,读者可以学会如何提出假设、寻找证明以及使用数学推理来解决问题。这些技巧对于发展数学思维、逻辑推理和问题解决能力非常重要。 《问题解决的艺术:几何学PDF》适合那些对几何学感兴趣的学生和数学爱好者。它扩展了读者对几何学的了解,并培养了他们解决复杂问题的能力。对于准备参加数学竞赛或追求数学学科的学生来说,这本书是一个很好的学习资源。 总之,《问题解决的艺术:几何学PDF》是一本有益的几何学学习资料,它向读者展示了解决几何学问题的方法和技巧。通过学习这本书,读者可以提高自己的几何学知识和解决问题的能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值