ZOJ - 3806 :Incircle and Circumcircle

A triangle is one the basic shapes in geometry. It's a polygon with three vertices and three sides which are line segments. A triangle with vertices AB, C is denoted ΔABC. And its three sides, BCCAAB are often denoted ab and c.

The incircle of a triangle is the largest circle contained in the triangle, it is tangent to the three sides. The center of the incircle is called the triangle's incenter and the radius of the incircle is called inradius, which is denoted r.

The circumcircle of a triangle is the circle which passes through all its three vertices. The center of the this circle is called circumcenter and its radius is called circumradius, which is denoted R.

It's very easy to calculate r and R after knowing ab and c. Now you are given rand R, can you calculate a valid triple (abc)?

Input

There are multiple cases. Each case has two positive integers r and R in one line. (r and R are less than 105)

Ouput

For each case, print three floating numbers ab and c in one line if it's possible to get r and R. If there are no possible tuples, print "NO Solution!".

The judge program uses your ab and c to calculate the inradius and circumradius. Only the relative error of your inradius and circumradius less than 10-8 will be accepted.

Sample Input
1 2
2 5
9 9
Sample Ouput
3.464101615137754587 3.464101615137754587 3.464101615137754587
6 8 10
NO Solution!

思路:http://www.cnblogs.com/Silence-AC/p/3935014.html

#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
    double r,R;
    while(cin>>r>>R)
    {
        if(R<2*r){puts("NO Solution!");continue;}
        double down=0,up=sqrt(3)*R,mid,a;
        while(up-down>1e-10) //二分枚举底边长
        {
            mid=(up+down)/2;
            a=sqrt((sqrt(R*R-(mid*mid)/4)+R)*(sqrt(R*R-(mid*mid)/4)+R)+(mid*mid)/4); //等腰三角形的腰长
            double p=(a+a+mid)/2;

            //三角形内切圆半径公式 r=2*S/(a+b+c) (S为三角形面积,a,b,c分别是三角形三条边)
            if(2*sqrt(p*(p-a)*(p-a)*(p-mid))/(a+a+mid)-r>1e-12)
            {
                up=mid;
            }
            else down=mid;
        }
        printf("%0.16lf %0.16lf %0.16lf\n",a,a,mid);
    }
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值