您的位置:首页 > 其它

poj_1905 Expanding Rods(二分求单调函数)

2016-12-05 16:54 561 查看
Expanding Rods
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 15684 Accepted: 4160
DescriptionWhen 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.InputThe 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. Inputdata 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.OutputFor 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
设θ为圆心角的一半,r为半径,h为要求的高度,则有
(1)sinθ = (L/2)/r;
(2)r^2 = (L/2)^2 + (r-h)^2;
(3)2*θ*r = L';
可得方程
r = (4*h^2+L^2)/(8*h);
L' = 2 * arcsin(L/(2*r)) * r;
之后就用二分法求单调函数,注意精度,太小WA,太大可能TLE。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <stack>#include <bitset>#include <queue>#include <set>#include <map>#include <string>#include <algorithm>#define FOP freopen("data.txt","r",stdin)#define FOP2 freopen("data1.txt","w",stdout)#define inf 0x3f3f3f3f#define maxn 1000010#define mod 1000000007#define PI acos(-1.0)#define LL long longusing namespace std;double n, C, L, L2;double f(double h){double r = (h*h*4 + L*L) / (h*8.0);return asin(L/(r*2.0)) * r * 2;}int main(){while(~scanf("%lf%lf%lf", &L, &n, &C) && (L != -1)){L2 = (1 + n * C) * L;double l = 0, r = L/2, m;while(r - l > 1e-4){m = (l+r)/2;if(f(m) < L2) l = m;else r = m;}printf("%.3f\n", m);}return 0;}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: