UVA375Inscribed Circles and Isosceles Triangles

来源:互联网 发布:想念的人在社交网络 编辑:程序博客网 时间:2024/06/01 09:51

UVA-375

题意:等腰三角形给出底边和高,首先求内切圆r1,再求切两腰和r1的圆r2,同理求r3……知道圆的半径小于0.000001。求这些圆的周长和。
解题思路:我们可以求出腰长 x=srqt( h*h+b*b*0.25) , 内切圆半径 r = 2*s/ c(c是周长) = h*b /(x+x+b)。后面的每一个圆要切前一个圆和两腰,过前一个圆作直线平行底边,上面的小三角行和整个三角形相似,而且每个小三角形和比它大的那个的比例都是想同的,所以两个r的比例也是相同的。这个比例t = (h- r*2)/h;
然后圆周率不要手打3.1415926……,用cmat里面的 acos(-1.0) 。

#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>#include <cmath>using namespace std;double b,h,r,sum,s,x,pi;int main () {    freopen("xx.in","r",stdin);    freopen("xx.out","w",stdout);    int n;    pi= acos(-1.0);    scanf("%d",&n);    while (n--) {        scanf("%lf%lf",&b,&h);        sum=0;        x=sqrt(h*h+b*b*0.25);        r=h*b/(x+x+b);        h = (h - 2.0*r) / h;        while (r > 0.000001) {            sum+=r;            r= r*h;        }        printf("%13.6lf\n",pi*2.0*sum);        if (n) printf("\n");    }}
0 0
原创粉丝点击