Inscribed Circles and Isosceles Triangles |
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
三角形内部无限画内切圆直到半径小于0.000001,求这些内切圆的周长之和
此题的重点在于求三角形内心的位置,用到了下面这条性质:
设三角形面积为S,三个边长分别为a,b,c,则内切圆半径为:2*S/(a+b+c)
此题中为等腰三角形,内心在底边的高线上,求出半径就求出了内心的位置,进而可以求下一个内心和下一个半径
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #define PI 3.1415926535897932384626 5 6 using namespace std; 7 8 int main() 9 { 10 int kase; 11 12 scanf("%d",&kase); 13 14 while(kase--) 15 { 16 double b,h; 17 18 scanf("%lf %lf",&b,&h); 19 20 double total=0; 21 22 while(true) 23 { 24 double tmp=sqrt(b*b/4+h*h); 25 double c=tmp*2+b; 26 double s=h*b; 27 double r=s/c; 28 if(r<0.000001) 29 break; 30 total+=r; 31 b-=2*r*b/h; 32 h-=2*r; 33 } 34 35 printf("%13.6f\n",2*PI*total); 36 37 if(kase) 38 putchar(‘\n‘); 39 } 40 41 return 0; 42 }
UVa 375 Inscribed Circles and Isosceles Triangles
原文:http://www.cnblogs.com/lzj-0218/p/3536727.html