Expanding Rods
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 15096 | Accepted: 4009 |
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 (取代).
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
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
题意:某种材料制作的长杆,现在因为温度升高而出现隆起,现在问你隆起的高度是多少。
我们假设隆起的高度的是h,则h和圆弧的半径r以及圆弧的长度(次l)之间的关系有:
第一个勾股定理就可以出来,第二个根据弧长等于弧度乘上半径就可以出来。
然后我们二分查找答案,确保我们求得的l和题目所给的l1的值相差到某个级位就可以。
范围就是0~h/2辣
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
typedef long long ll;
using namespace std;
const int inf=0x3f3f3f;
const int MAXN=50000+10;
double eps=1e-5;
int main()
{
double l,n,c;
while(~scanf("%lf%lf%lf",&l,&n,&c))
{
if(l<0&&n<0&&c<0)break;
double low=0.0,high=l*0.5,mid;
double l1,r;
l1=l*(1.0+n*c);
while(high-low>eps)//测试到1e-5才可以
{
mid=(high+low)/2.0;
r=(4*mid*mid+l*l)/(8*mid);
if(2*r*asin(l*0.5/r)<l1)low=mid;
else high=mid;
}
printf("%.3f\n",mid);
}
return 0;
}