# Expanding Rods解题报告

182人阅读 评论(0)

The input contains multiple lines. Each line of input contains three non-negative numbers: the initial lenth of the rod in millimeters, the temperature change in degrees and the coefficient of heat expansion of the material. Input data guarantee that no rod expands by more than one half of its original length. The last line of input contains three negative numbers and it should not be processed.

Output

For each line of input, output one line with the displacement of the center of the rod in millimeters with 3 digits of precision.

Sample Input

1000 100 0.0001
15000 10 0.00006
10 0 0.001
-1 -1 -1


Sample Output

61.329
225.020
0.000
#include<iostream>
#include<cmath>
using namespace std;
const double ep=1e-12;
const double pi=acos(0.0);
int main()
{
double n,c,L;
while(scanf("%lf%lf%lf",&L,&n,&c)!=EOF)
{
if(L==-1&&n==-1&&c==-1)
break;
else
{
double a;
a=(1+n*c)*L;   //L'的公式。
double low=0,high=pi,mia;
while(low+ep<high)  //精确范围。
{
mia=(low+high)/2.0;  //(0,PI)中二分查找。
if(sin(mia)/mia>L/a)
{
low=mia;
}
else
high=mia;
}
printf("%.3lf\n",(1-cos(high))*L/(2*sin(high)));
}
}
return 0;
}
0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：84152次
• 积分：1237
• 等级：
• 排名：千里之外
• 原创：45篇
• 转载：14篇
• 译文：0篇
• 评论：6条
评论排行
最新评论