首页 > 代码库 > UVA - 1356 Bridge
UVA - 1356 Bridge
Description
A suspension bridge suspends the roadway from huge main cables, which extend from one end of the bridge to the other. These cables rest on top of high towers and are secured at each end by anchorages. The towers enable the main cables to be draped over long distances.
Suppose that the maximum distance between two neighboring towers is D , and that the distance from the top of a tower to the roadway isH . Also suppose that the shape of a cable between any two neighboring towers is the same symmetric parabola (as shown in the figure). Now givenB , the length of the bridge and L , the total length of the cables, you are asked to calculate the distance between the roadway and the lowest point of the cable, with minimum number of towers built (Assume that there are always two towers built at the two ends of a bridge).
Input
Standard input will contain multiple test cases. The first line of the input is a single integerT(1T10) which is the number of test cases. T test cases follow, each preceded by a single blank line.
For each test case, 4 positive integers are given on a single line.
- D
- - the maximum distance between two neighboring towers;
- H
- - the distance from the top of a tower to the roadway;
- B
- - the length of the bridge; and
- L
- - the total length of the cables.
It is guaranteed that BL . The cable will always be above the roadway.
Output
Results should be directed to standard output. Start each case with "Case # : " on a single line, where # is the case number starting from 1. Two consecutive cases should be separated by a single blank line. No blank line should be produced after the last test case.
For each test case, print the distance between the roadway and the lowest point of the cable, as is described in the problem. The value must be accurate up to two decimal places.
Sample Input
2 20 101 400 4042 1 2 3 4
Sample Output
Case 1: 1.00 Case 2: 1.60 题意:修桥,桥上等距的摆放着若干个塔,塔高为H,相邻两座塔之间的距离不超过D,塔之间的绳索形成全等的对称抛物线,桥长度为B,绳索长为L,问你绳索最下端离地的高度y。思路间隔数为n=ceil(B/D),每个间隔的宽度D1=B/n,每段的绳索长度为L1=L/n,然后根据D1和L1计算离地的高度,我们可以先求出一个抛物线,当开口宽度为w,高度为h的时候抛物线的长来二分求解,这里就需要高数的公式求可导函数的弧长了#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; double F(double a, double x) { double a2 = a * a, x2 = x * x; return (x * sqrt(a2 + x2) + a2 * log(fabs(x + sqrt(a2 + x2)))) / 2; } double cal_length(double w, double h) { 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() { int t, cas = 1; scanf("%d", &t); while (t--) { int D, B, H, L; scanf("%d%d%d%d", &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) { double m = x + (y - x) / 2; if (cal_length(D1, m) < L1) x = m; else y = m; } if (cas > 1) printf("\n"); printf("Case %d:\n%.2lf\n", cas++, H-x); } return 0; }
UVA - 1356 Bridge