uva 375 Inscribed Circles and Isosceles Triangles(等腰三角形内接圆)

来源:互联网 发布:手机ping软件 编辑:程序博客网 时间:2024/06/06 10:53

题意是给你等腰三角形的底长和高,求其内接圆内接圆内接圆内接圆......直到精度到达上限的周长和。

如图:


可得:

tan(angle) = h / d.

tan(angle / 2) = r / (d / 2).

联立上两式,可得:

angle = atan(h / (b / 2)).

r = tan(angle / 2) * b / 2.


于是,小一层的等腰三角形:

h' = h - 2 * r.

三角形相似:

d' / d = h' / h.

联立上俩式得:

b = b * (h - 2 * r) / h.


此刻又转回了第一层的问题,循环到题目要求的精度就行了。注意输出格式。


代码:

#include <stdio.h>#include <math.h>const double Pi = acos(-1.0);const double eps = 1e-6;int main(){    int ncase;    scanf("%d", &ncase);    while (ncase--)    {        double b, h;        scanf("%lf%lf", &b, &h);        double sum = 0;        while (1)        {            double angle = atan(h / (b / 2));            double r = tan(angle / 2) * b / 2;            if (r < eps)                break;            sum += 2 * r * Pi;            b = b * (h - 2 * r) / h;            h = h - 2 * r;        }        printf("%13.6lf\n", sum);        if (ncase)            printf("\n");    }    return 0;}


0 0
原创粉丝点击