uva 375 Inscribed Circles and Isosceles Triangles(相似三角形)

來源:互聯網
上載者:User

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

10.263451 0.263451
Sample Output
     0.827648


題目大意:圖片從別人哪裡拷貝的,覺得解釋的很清楚。

解題思路:最早用

leap = sqrt(b * b + h * h);  r = (b * h * 0.5) / (leap +b);

的方法,但是涉及到除法,精度有誤差,所以WA了。

#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;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.