ZOJ3806 二分计算几何eps控制精度

Incircle and Circumcircle

Time Limit: 2 Seconds      Memory Limit: 65536 KB      Special Judge

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 A, B, C is denoted ΔABC. And its three sides, BC, CA, AB are often denoted a, b 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 a, b and c. Now you are given r and R, can you calculate a valid triple (a, b, c)?

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 a, b 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 a, b 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!
 
调那俩eps调到蛋疼。。。
假设是等腰三角形二分三角形的高就好了,需要一些计算公式~写的挺蛋疼。。
#define DeBUG
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <set>
#include <sstream>
#include <map>
#include <list>
#include <bitset>
using namespace std ;
#define zero {0}
#define INF 0x3f3f3f3f
#define EPS 1e-8
#define TRUE true
#define FALSE false
typedef long long LL;
const double PI = acos(-1.0);
//#pragma comment(linker, "/STACK:102400000,102400000")
inline int sgn(double x)
{
    return fabs(x) < EPS ? 0 : (x < 0 ? -1 : 1);
}
#define N 100005
double R, rr;
double geta(double c)
{
    double x = sqrt(R * R - c * c / 4.0);
    double a = sqrt((R - x) * (R - x) + c * c / 4.0);
    return a;
    // return sqrt((R - sqrt(R * R - c * c / 4.0)) * (R - sqrt(R * R - c * c / 4.0)) + c * c / 4.0);
}
double getadown(double c)
{
    double x = sqrt(R * R - c * c / 4.0);
    double a = sqrt((R + x) * (R + x) + c * c / 4.0);
    return a;
}
double getr(double c)
{
    double a = geta(c);
    return (2.0 * R * a * c - R * c * c) / (2.0 * a * a);
}
double getr2(double c)
{
    double a = getadown(c);
    return (2.0 * R * a * c - R * c * c) / (2.0 * a * a);
}
int main()
{
#ifdef DeBUGs
    freopen("C:\\Users\\Sky\\Desktop\\1.in", "r", stdin);
#endif

    const double epsget = 1e-13;
    while (scanf("%lf%lf", &rr, &R) + 1)
    {
        if (sgn(2 * rr - R) > 0)
        {
            printf("NO Solution!\n");
        }
        else
        {
            double l = 0.0;
            double r = R * 2;
            double mid;
            double nowr;
            int flag = 0;
            while (sgn(l-r) < 0)
            {
                // cout << "1" << flag << endl;
                mid = (l + r) / 2.0;
                nowr = getr(mid);
                if (sgn( nowr - rr) < 0)
                    l = mid + epsget;
                else if (sgn( nowr - rr) > 0)
                    r = mid - epsget;
                else
                {
                    flag = 1;
                    break;
                }
            }
            if (!flag)
            {
                l = sqrt(3) * R;
                r = 2 * R;
                while (sgn(l-r) < 0)
                {
                    // cout << "2" << flag << endl;
                    mid = (l + r) / 2.0;
                    nowr = getr2(mid);
                    if (sgn( nowr - rr) > 0)
                        l = mid + epsget;
                    else if (sgn(nowr - rr) < 0)
                        r = mid - epsget;
                    else
                    {
                        flag = 2;
                        break;
                    }
                }
            }
            // 3.464101615137754587
            if (flag == 1)
            {
                printf("%.20lf %.20lf %.20lf\n", geta(mid), geta(mid), mid);
            }
            else if (flag == 2)
            {
                printf("%.20lf %.20lf %.20lf\n", getadown(mid), getadown(mid), mid);
            }
            else
            {
                printf("NO Solution!\n");
            }

        }
    }

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值