点击打开题目
1137 - Expanding Rods
PDF (English) | Statistics | Forum |
---|
Time Limit: 0.5 second(s) | Memory Limit: 32 MB |
---|
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. That means you have to calculate h as in the picture.
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case contains three non-negative real numbers: the initial length of the rod in millimeters L, the temperature change in degrees n and the coefficient of heat expansion of the material C. Input data guarantee that no rod expands by more than one half of its original length. All the numbers will be between 0 and 1000 and there can be at most 5 digits after the decimal point.
For each case, print the case number and the displacement of the center of the rod in single line. Errors less than 10-6 will be ignored.
Sample Input | Output for Sample Input |
---|---|
3 1000 100 0.0001 150 10 0.00006 10 0 0.001 | Case 1: 61.3289915 Case 2: 2.2502024857 Case 3: 0 |
主要是几何分析,这里我就不一点点画图了,给一个链接,分析的就很好:点击打开链接
代码如下:
#include <cstdio>
#include <cmath>
int main()
{
double left,right,mid;
double l,n,s,c;
double r;
int Case = 1;
int u;
scanf ("%d",&u);
while (u--)
{
scanf ("%lf %lf %lf",&l,&n,&c);
printf ("Case %d: ",Case++);
s = (1.0+n*c)*l;
left = 0;
right = l / 2.0;
while (right - left > 1e-8)
{
mid = (right + left) / 2.0;
r = (l*l + 4*mid*mid) / (8*mid);
double t = asin(l/2/r);
if (t * r * 2.0 < s)
left = mid;
else
right = mid;
}
printf ("%.6lf\n",left);
}
return 0;
}