Ultraviolet A 10668-expanding Rods
Question Link
Given an iron rod, the heating will become an arc. The length isL'= (1 +NC)LAnd the height of the original location.
Idea: Draw a formula that can easily be used to calculate the length of the iron rod by setting the arc slice radian R.LR/SIN(R) This formula is monotonically increasing in [0, PI/2]. Therefore, it can be solved using the bipartite method.
It should be noted that the final answer is brought into the mid during the calculation process, which is previously brought into the X (left value of the binary). In fact, X may be equal to 0, but brought into the mid, because it is a double type, mid actually indicates a number that is very close to 0, rather than 0.
Code:
#include <cstdio>#include <cstring>#include <cmath>const double pi = acos(-1.0);double l, n, c;double cal(double r) { return l / sin(r) * r;}int main() { while (~scanf("%lf%lf%lf", &l, &n, &c)) {if (l < 0) break;double x = 0, y = pi / 2, lx = (1 + n * c) * l, m;for (int i = 0; i < 100; i++) { m = (x + y) / 2; if (cal(m) < lx) x = m; else y = m;}printf("%.3lf\n", l / 2 / sin(m) * (1 - cos(m))); } return 0;}