UVAOJ 375 基础题 内接圆和等腰三角形 几何计算

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=311
 Inscribed Circles and Isosceles Triangles 

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 /*************************************************************************
 2     > File Name: 12345.cpp
 3     > Author: acmicpcstar
 4     > Mail: acmicpcstar@gmail.com
 5     > Created Time: 2014年04月24日 星期四 11时46分18秒
 6  ************************************************************************/
 7 
 8 #include<iostream>
 9 #include<cstring>
10 #include<cstdio>
11 #include<cmath>
12 using namespace std;
13 const double pi=atan(1.0)*4.0;
14 int main()
15 {int T;
16 double b,h,sum,r,k;
17 cin>>T;
18 while(T--)
19 {cin>>b>>h;
20 sum=0.0;
21 k=b/2/(sqrt(b*b/4+h*h)+b/2);
22 r=k*h;
23 while(r>0.000001)
24 {
25 sum+=r;
26 h=h-2*r;
27 r=k*h;
28 }
29 printf("%13.6lf\n",pi*2*sum);
30 if(T) printf("\n");
31 }
32 return 0;
33 }

 

 

调了好久。。。2处错误。。。开始精度不过关。。。我们后来发现R和H比例是不变的。。开始的做法不断R和H减小 这样会让精度下降。。。后来看了别人代码就过了。。。printf13.6。。。13包括小数点~

posted @ 2014-04-24 12:53  acmicpcstar  阅读(206)  评论(0编辑  收藏  举报