Description
When a thin rod of length L is heated n degrees, it expands to a new length L'=(1+n*C)*L, where C is the coefficient of heat expansion. When a thin rod is mounted on two solid walls and then heated, it expands and takes the shape of a circular segment, the original rod being the chord of the segment.
Your task is to compute the distance by which the center of the rod is displaced.
Input
Output
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
这道题的题意相当于一个圆知道一条切割的弦长跟对应的弧长,然后求这条弦到对应弧最高点的距离。
几何关系如下:sin(a)=l/2/r,a=s/2/r.(a为角度,s为弧长)。然后用二分查找进行求值。
源代码如下:
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main()
{
double l,n,c,s,r,low,high,mid;
while(scanf("%lf%lf%lf",&l,&n,&c)&&l!=-1&&n!=-1&&c!=-1)
{
low=0,high=0.5*l;
s=(1+n*c)*l;
while(high-low>1e-5)
{
mid=(low+high)/2;
r=(4*mid*mid+l*l)/(8*mid);
if(2*r*asin(l/(2*r))<s) low=mid;
else high=mid;
}
printf("%.3f\n",mid);
}
return 0;
}
需要注意的是输入输出要用scanf跟pritnf。循环条件到1e-5即可,再小的话可能就超时了。
本文介绍了一种计算受热膨胀的细杆中心位移的方法,通过解析几何关系并使用二分查找法求解,最终输出精确到三位小数的位移结果。
648

被折叠的 条评论
为什么被折叠?



