UVA 375 - Inscribed Circles and Isosceles Triangles
程序员文章站
2022-04-01 13:35:59
...
题目大意:一个等腰三角形的内切圆,以及这个内切圆与等腰三角形两腰的内切圆,一直往下求内切圆,知道内切圆半径小于0.000001。求所有内切圆的周长和。
解题思路:先求出第一个内切圆的半径(底边与高的乘积除以三角形周长等于内切圆的半径),之后的内切圆半径都是按比例缩小。
ac代码:
#include <iostream>
#include <cmath>
#define Pi acos(-1.0)
using namespace std;
int n;
double width, high, waist, high2, ratio;
double r, circle;
int main()
{
scanf("%d", &n);
while (n--){
scanf("%lf%lf", &width, &high);
circle = 0;
waist = sqrt( pow(width/2, 2) + pow(high, 2));
r = high * width / (width + 2 * waist);
high2 = high - 2 * r;
ratio = high2 / high;
while (r > 0.000001){
circle += 2*Pi*r;
r *= ratio;
}
printf("%13.6lf\n", circle);
if (n)
printf("\n");
}
return 0;
}