UVA375 UVALive5347 Inscribed Circles and Isosceles Triangles【等腰三角形内切圆】

Given two real numbers
    B the width of the base of an isoceles triangle in inches
    H the altitude of the same isoceles triangle in inches
Compute to six significant decimal places
    C the sum of the circumferences of a series of inscribed circles stacked one on top of another from the base to the peak; such that the lowest inscribed circle is tangent to the base and the two sides and the next higher inscribed circle is tangent to the lowest inscribed circle and the two sides, etc. In order to keep the time required to compute the result within reasonable bounds, you may limit the radius of the smallest inscribed circle in the stack to a single recision floating point value of 0.000001.
    For those whose geometry and trigonometry are a bit rusty, the center of an inscribed circle is at the point of intersection of the three angular bisectors.
Input
The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.
    The input will be a single line of text containing two positive single precision real numbers (B H) separated by spaces.
Output
For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.
    The output should be a single real number with twelve significant digits, six of which follow the decimal point. The decimal point must be printed in column 7.
Sample Input
1
0.263451 0.263451
Sample Output
        0.827648

Regionals 1990 >> North America - Rocky Mountain

问题链接UVA375 UVALive5347 Inscribed Circles and Isosceles Triangles
问题简述:(略)
问题分析
    计算等腰三角形的内切圆周长之和,三角形内切圆之后,继续用内切圆与等腰三角形两腰的内切圆进行计算下去,直到内切圆半径小于精度0.000001。
    采用迭代计算,直到满足精度要求为止。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA375 UVALive5347 Inscribed Circles and Isosceles Triangles */

#include <bits/stdc++.h>

using namespace std;

const double PI = acos(-1.0);
const double EPS = 1e-6;

int main()
{
    int t;
    scanf("%d", &t);
    while(t--) {
        double b, h, sum = 0;

        scanf("%lf%lf", &b, &h);
        for(;;) {
            double l = atan(h / b * 2);
            double r = tan(l / 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(t) printf("\n");
    }

    return 0;
}

猜你喜欢

转载自www.cnblogs.com/tigerisland45/p/10425625.html