D - Expanding Rods POJ - 1905(二分)

D - Expanding Rods POJ - 1905

D - Expanding Rods POJ - 1905(二分)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
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
Sponsor

思路

  • 利用数学中的 几何等式 建立方程,利用二分答案 来一个一个进行 尝试答案

题解

//Memory Time
//244K 0MS #include<iostream>
#include<math.h>
#include<iomanip>
using namespace std; const double esp=1e-5; //最低精度限制 int main(void)
{
//freopen("A.txt","r",stdin);
double L,n,c,s; //L:杆长 ,n:温度改变度 , c:热力系数 ,s:延展后的杆长(弧长)
double h; //延展后的杆中心 到 延展前杆中心的距离
double r; //s所在圆的半径 while(cin>>L>>n>>c)
{
if(L<0 && n<0 && c<0)
break; double low=0.0; //下界
double high=0.5*L; // 0 <= h < 1/2L (1/2L并不是h的最小上界,这里做一个范围扩展是为了方便处理数据) double mid;
s=(1+n*c)*L;
while(high-low>esp) //由于都是double,不能用low<high,否则会陷入死循环
{ //必须限制low与high的精度差
mid=(low+high)/2;
r=(4*mid*mid+L*L)/(8*mid); if( 2*r*asin(L/(2*r)) < s ) //h偏小
low=mid;
else //h偏大
high=mid;
}
h=mid; cout<<fixed<<setprecision(3)<<h<<endl;
}
return 0;
}
上一篇:两道二分coming~


下一篇:设置cas server使用http非安全协议