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
题目大意:图片从别人哪里拷贝的,觉得解释的很清楚。
解题思路:最早用
leap = sqrt(b * b + h * h); r = (b * h * 0.5) / (leap +b);
#include<stdio.h> #include<iostream> #include<math.h> using namespace std; int main(){ double b, h; int t; const double pi = 4 * atan(1.0); cin >> t; while (t--){ cin >> b >> h; double sum = 0; while (1){ double leap = atan(h /(b / 2)); double r = tan(leap / 2) * b / 2; if (r < 0.000001) break; sum += 2 * pi * r; b = b * (h - 2 * r) / h; h = h - 2 * r; } printf("%13.6lf\n", sum); if (t) cout << endl; } return 0;}