Example 2.28 rope UVa1356 on a bridge

Source: Internet
Author: User

1. Title Description: Click to open the link

2. Problem-Solving ideas: The topic is a calculus, first of all according to the conditions of the problem of the equation: Interval number N=ceil (b/d), each interval width d1=b/n, each length of rope l1=l/n. The next step is to calculate the height of the bottom from the ground on the d1,l1 to Y. However, we will find that this equation is difficult to find the formula, so we should transfer the idea, trying to use the binary method of numerical problems to gradually approximate the height value. The function P (w,h) calculates the length of the parabola, where w represents the width of the parabolic aperture, h denotes the height of the parabolic line, then it is not difficult to find that this function is a monotone function: When w is fixed, it increases with the increase of H. Because the parabola length is also determined, the height H can be solved by the dichotomy method at this time.

So, how to calculate P (w,h) This function, we can use the arc length formula in calculus to calculate the arc length, at the same time can look up the table to find the original function of the arc length formula, so as to obtain the arc length, the specific process is omitted.

3. Code:

#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std;typedef long long ll;double F (double A, Double x)//sqrt (a^2+x^2) of the original function {Double a2 = a*a, x2 = X*x;return (x*sqrt (A2 + x2) + a2*log (fabs (x + sqrt (a2 + x2)))/2;} Double P (double W, double h)//Arc length {Double A = 4.0*h/w/w;double b = 1.0/2/A;return (f (b, W/2)-F (b, 0)) * 4 * A;} int main () {freopen ("T.txt", "R", stdin), int t;cin >> t;for (int rnd = 1; Rnd <= T; rnd++) {int D, h, B, L;cin >  > D >> h >> b >> l;int n = (b + d-1)/d;double D1 = (double) b/n;double L1 = (double) l/n;double x = 0, y = h;while (y-x > 1e-5)//Use the Dichotomy method to solve the height h{double m = x + (y-x)/2;if (P (D1, M) < L1) x = M;else y = m;} if (rnd>1) cout << endl;printf ("Case%d:\n%.2lf\n", Rnd, h-x);} return 0;}



Example 2.28 rope UVa1356 on a bridge

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.