Given two real numbers
Compute to six significant decimal places
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.
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.
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.
1 0.263451 0.263451
0.827648
给你一个等腰三角形,告诉你底边B,和对应的高H。做该三角形的内切圆。然后再做一个小圆,相切与三角形的两腰,同时切于该大圆。以此类推,一直切下去,知道精度达到1e-6
思路:这道题其实是有规律的,大圆和小圆的半径是成比例的。我一开始直接是用累加的思想,结果得到的答案和样例有误。后来看了别人的阶梯报告,直接用原先的高度H减去最后的高度h,得到的就是所有圆形的直径之和,这相对累加的精度应该要高。
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define PI acos(-1.0) using namespace std; int main () { int t; double b,h,h1,sum=0,r,c,a,H,R; cin>>t; while(t--) { sum=0; cin>>b>>h; a=sqrt(b*b/4.0+h*h); r=h*b/(2*a+b); H=h; R=r; while(r>=1e-6) { h1=h; h=h-2*r; r=h*R/H; } printf("%13.6lf\n",(H-h)*PI); if (t!=0) printf("\n"); } return 0; }