Expanding Rods
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 13354 | Accepted: 3442 |
Description

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
方程容易求的。
最后直接枚举答案。(SL为起始长度, L为之后长度)
不过本题有两个坑点。
1、Input data guarantee that no rod expands by more than one half of its original length.(如果R取太大了,答案肯定是错了的, R应取SL / 4, 保险也可取 SL / 2)。
2、二分循环当循环量很大时, 用浮点数可能有误差。
#include <cstdio> #include <iostream> #include <cstring> #include <algorithm> #include <cstdlib> #include <set> #include <string> #include <cmath> #include <stack> #include <queue> #include <map> #include <vector> #define FOR(i, a, b) for(int i = a; i < b; i++) #define mem(a) memset(a, 0, sizeof(a)) using namespace std; //typedef __int LL; typedef long long LL; const double epx = 1e-7; int main() { double sl, l, r, n, c; while (scanf("%lf %lf %lf", &sl, &n, &c), sl >= 0 && n >= 0 && c >= 0) { l = (1 + n * c) * sl; double L = 0.0, R = sl / 4; FOR(i, 0, 1000) { //这里是重点。 double mid = (L + R) / 2; r = mid / 2 + (sl * sl) / (8 * mid); if (r >= (l / (2 * asin(sl / (2 * r))))) R = mid; else L = mid; } printf("%.3lf\n", L); } return 0; }