POJ1905 Expanding Rods(二分)
题意:
给一个长度为L的钢条,加热后长度改变并且弯曲成一个弧,算出之间的距离
要点:
基础思想是二分,但其实里面包含了很多证明
参考博客:点击打开链接
15301383 | Seasonal | 1905 | Accepted | 196K | 0MS | C++ | 510B | 2016-03-22 20:56:20 |
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
double l, n, c,L;
double r;
double depart(double left, double right)
{
double h, r, ll;
while (right-left>0.000001)//精确度6位
{
h = (left + right) / 2.0;
r = (4 * h*h + l*l) / (8 * h);
ll = 2 * r*asin(l / (2 * r));
if (ll > L)
right = h;
else
left = h;
}
return h;
}
int main()
{
while (~scanf("%lf%lf%lf", &l, &n, &c))
{
if (l == -1)
break;
L = l*(1 + n*c);
printf("%.3lf\n", depart(0, l / 2.0));
}
return 0;
}