《题意:等腰三角形,给你底和高,即B和H,从底向上不断摞内切圆,其中最底下的跟底和两腰都相切,往上的跟两腰和下面的圆相切,不断继续,直到圆半径达到题目给定的精度位置。计算所有这些圆的周长之和。
解法:周长好求,知道了高,也就是累到最后一个圆时在H上的高度为d,那么周长之和为c = pi * d;关键是怎么求d,发现每个圆的半径与其所在三角形的高的比是一定的,设当前三角形的高为p,由面积相等可以推出r = p * B/(B+2*A),其中A= sqrt(B*B/4+H*H),即腰的长度。
解法:周长好求,知道了高,也就是累到最后一个圆时在H上的高度为d,那么周长之和为c = pi * d;关键是怎么求d,发现每个圆的半径与其所在三角形的高的比是一定的,设当前三角形的高为p,由面积相等可以推出r = p * B/(B+2*A),其中A= sqrt(B*B/4+H*H),即腰的长度。
不断循环找到最后一个p,那么合法的高度和就是H-p;问题解决了。》
多么简单的推理 我当时怎么没想到啊l
可以设置个k=相似比;
大神代码
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double pi = acos(-1.0);
int main()
{
double b,h,r,c,k,l,p;
int t;
cin>>t;
while(t--)
{
cin>>b>>h;
l = sqrt(b*b/4+h*h);
k = b/(b+2*l);
p = h;
r = p*k;
while(r >= 0.000001)
{
p = p-2*r;
r = p*k;
}
c = pi*(h-r/k);
printf("%13.6lf\n",c);
if(t)putchar('\n');
}
return 0;
}
我的
#include <iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
int t;
double h,b,a;
cin>>t;
while(t--)
{
cin>>h>>b;
double H=h;
a=sqrt(b*b/4+h*h);
double r=h*b/(b+2*a);
double k=b/(b+2*a);
while(r>=0.000001)
{
h-=2*r;
r=h*k;
}
//cout<<h<<endl;
//cout<<H-h<<endl;
double l=3.141592653589793*(H-h);
cout<<setw(13)<<l<<endl;
if(t)
cout<<endl;
}
return 0;
}