`
阿尔萨斯
  • 浏览: 4177808 次
社区版块
存档分类
最新评论

zoj 3806 Incircle and Circumcircle(二分)

 
阅读更多

题目链接:zoj 3806 Incircle and Circumcircle

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

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

#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;
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics