09:膨胀的木棍
-
总时间限制:
- 1000ms 内存限制:
- 65536kB
-
描述
-
当长度为L的一根细木棍的温度升高n度,它会膨胀到新的长度L'=(1+n*C)*L,其中C是热膨胀系数。
当一根细木棍被嵌在两堵墙之间被加热,它将膨胀形成弓形的弧,而这个弓形的弦恰好是未加热前木棍的原始位置。
你的任务是计算木棍中心的偏移距离。
输入
-
三个非负实数:木棍初始长度(单位:毫米),温度变化(单位:度),以及材料的热膨胀系数。
保证木棍不会膨胀到超过原始长度的1.5倍。
输出
- 木棍中心的偏移距离(单位:毫米),保留到小数点后第三位。 样例输入
-
1000 100 0.0001
样例输出
-
61.329
来源
- Waterloo local 2004.06.12
-
- 点评:二分求角的极限法 参考 http://www.cnblogs.com/huashanqingzhu/p/5662002.html
-
-
#include <stdio.h>
#include <iostream>
#include <stack>
#include <string.h>
#include <queue>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
using namespace std;
typedef long long LL;
#define MAX 100001
int a[MAX];
int b[MAX];
int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
double L_before; //原始长度
double L_After; //形变后的长度
double rig, lef, mid; //角的极大极小值
double n, c;
scanf("%lf%lf%lf", &L_before, &n, &c);
if(L_before < 1e-14){
printf("0.000\n");
return 0;
}
L_After = L_before * (1 + n * c);
lef = 0.0; //角的极小值
rig = asin(1.0); //角的极大值
while(rig - lef>1e-14){
mid = (rig + lef) / 2;
if(L_After * sin(mid) / mid <= L_before){
rig = mid;
}else {
lef = mid;
}
}
printf("%.3lf\n", L_before / 2 * tan(lef / 2));
return 0;
}