Ultraviolet A 10668-expanding rods (Mathematics + binary)

Source: Internet
Author: User
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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.