UVa 375 Inscribed Circles and Isosceles Triangles (等腰三角形内切圆&规律)

探讨了如何计算一系列内切于等腰三角形的圆的总周长,涉及几何与三角函数的应用,通过递归减小圆的半径直至达到预定精度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

375 - Inscribed Circles and Isosceles Triangles

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_problem&problem=311

Given two real numbers

B
the width of the base of an isosceles triangle in inches
H
the altitude of the same isosceles 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 precision 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


1. 如何求内切圆半径?——过内心向三条边做垂线,再链接内心与三个顶点,由面积相等得0.5*(a+b+c)*r = 三角形面积S,即r=2*S/(a+b+c)

2. 下一个圆的半径呢?把公式中的高H和底B换成H-2r和B*(H-2r)/H即可——进而发现序列r成了一个等比序列。(但O(1)的公式法实现会存在精度不准的问题,不可行)


完整代码:

/*0.069s*/

#include<cstdio>
#include<cmath>
const double pi = 2 * acos(0);

int main()
{
	int n;
	double B, H, r, k, R;
	scanf("%d", &n);
	while (n--)
	{
		scanf("%lf%lf", &B, &H);
		r = B * H / (B + sqrt(B * B + 4 * H * H));
		k = 1 - 2 * r / H;
		R = 0;
		while (r >= 1e-6)
		{
			R += r;
			r *= k;
		} 
		printf("%13.6f\n", pi * R * 2);///注意是13
		if (n) putchar(10);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值