码迷,mamicode.com
首页 > 其他好文 > 详细

zoj 3806 Incircle and Circumcircle(二分)

时间:2014-08-31 23:03:52      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   io   ar   for   sp   amp   

题目链接:zoj 3806 Incircle and Circumcircle

题目大意:给定三角形的内接圆半径和外切圆半径,求三角形的三边长。

解题思路:以等腰三角形去构造,确定外切圆半径的时候,内切圆半径的范围为0?3R,二分判断即可。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>

using namespace std;

double f (double a, double R) {
    double t = sqrt(R * R - a * a / 4) + R;
    return sqrt(t * t + a * a / 4);
}

double judge (double a, double b, double R) {
    return a * b * b / (2 * R  * (a + b + b));
}

double bsearch (double l, double R, double v) {
    double r = sqrt(3.0) * R;

    for (int i = 0; i < 1000; i++) {
        double mid = (l + r) / 2;
        double x = f(mid, R);
        if (judge(mid, x, R) > v)
            r = mid;
        else
            l = mid;
    }
    return (l + r) / 2;
}

int main () {
    int r, R;
    while (scanf("%d%d", &r, &R) == 2) {
        if (r * 2 > R)
            printf("NO Solution!\n");
        else {
            double a = bsearch(0, R, r);
            double b = f(a, R);
            printf("%.10lf %.10lf %.10lf\n", a, b, b);
        }
    }
    return 0;
}

zoj 3806 Incircle and Circumcircle(二分)

标签:style   http   color   os   io   ar   for   sp   amp   

原文地址:http://blog.csdn.net/keshuai19940722/article/details/38964161

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!