Reprinted please indicate the source: Thank you
Http://user.qzone.qq.com/289065406/blog/1301845324
General question:
A pole with two ends fixed on both sides of the wall is bent upon heating.
Calculate the distance between the pole's point position in the first and second states.
Solution:
Ry and Binary Mixture
, Blue is before bending, length is L
After the rod is bent in red, the length is S.
H is desired
Zhizhi
S = (1 + N * C) * l
Three relationships are obtained;
(1) angle → radian formula θ r = 1/2 * s
(2) trigonometric function formula sin θ = 1/2 * l/R
(3) theorem R ^ 2-(R-h) ^ 2 = (1/2 * l) ^ 2
The four relational expressions can be simplified.
Reverse Thinking solutions to binary equations:
Requires (1) type H, only the first R
However, because the formula (2) is a trigonometric function, it is difficult to directly evaluate R.
Therefore, we need to use the forward thinking to solve the equations:
Enumerate the values of H in the range of H, calculate the corresponding R, and determine the result (2) obtained by this R) (S = (1 + N * C) * l)
Obviously, the binary search .....
So what is the range of H?
The lower bound is naturally 0 (not curved)
Key Upper Bound
Mentioned in
Input data guarantee that no rod expands by more than one half of its original length.
That is, the input data must be ensured that no rod can be extended by more than half of its initial length.
That is, s max = 3/2 L
In theory, the upper formula can be substituted into the (1) (2) equations to obtain the minimum upper bound of H, but the actual operation is very difficult.
Therefore, a range extension can be made here to extend the upper bound of H to 1/2L. It is not difficult to prove that this value must be greater than the minimum upper bound of H, then the range of H is 0 <= H <1/2L
In this way, the mid value can be obtained by using the lower and upper bounds of the lower bounds, and the optimal mid is found so that the difference between the left and right sides of the (2) formula is within the precision range. Then, this mid is H.
Attention must be paid to precision issues.
Because the data is double, when low infinitely close to high, if the condition of binary search is while (low
For more information about precision processing, see my program.
// Memory time // 244 K 0 Ms # include <iostream> # include <math. h ># include <iomanip> using namespace STD; const double ESP = 1e-5; // minimum Precision Limit int main (void) {double L, N, C, S; // L: pole length, N: temperature change degree, C: thermal coefficient, S: extension pole length (arc length) Double h; // The distance from the center of the extended rod to the center of the extended rod is double r; // the radius of the circle where S is located while (CIN> L> N> C) {If (L <0 & n <0 & C <0) break; double low = 0.0; // lower limit double high = 0.5 * l; // 0 <= H <1/2L (1/2L is not the upper limit of H. Here, a range extension is made to facilitate data processing) Double mid; S = (1 + N * C) * l; while (high-low> ESP) // because they are both double, low <High, otherwise it will fall into an endless loop {// The accuracy difference between low and high must be limited mid = (low + high)/2; r = (4 * mid * Mid + L * l) /(8 * mid); If (2 * r * asin (L/(2 * r) <S)/h smaller low = mid; else // H large high = mid;} H = mid; cout <fixed <setprecision (3) <H <Endl;} return 0 ;}