1056 - Olympics
One of the most important tasks is to build the stadium. You are appointed as a programmer to help things out in certain matters - more specifically in designing and building the athletics tracks. After some study, you find out that athletics tracks have a general shape of a rectangle with two sliced circles on two ends. Now the turf that is placed inside this rectangle is prepared elsewhere and comes in different shapes - different length to width ratios. You know one thing for certain - your track should have a perimeter of 400 meters. That's the standard length for athletics tracks. You are supplied with the design parameter - length to width ratio. You are also told that the sliced circles will be such that they are part of the same circle. You have to find the length and width of the rectangle.The next Olympic is approaching very shortly. It's a hard job for the organizers. There are so many things to do - preparing the venues, building the Olympic village for accommodating athletes and officials, improving the transportation of the entire city as the venues are located all over the city and also there will be great number of tourists/spectators during the Olympics.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.
Each case starts with the ratio of the length and width of the rectangle in the format: "a : b". Here, a and b will be integers and both will be between 1 and 1000 (inclusive).
Output
For each case, print the case number, the length and the width. Errors less than 10-6 will be ignored.
Sample Input |
Output for Sample Input |
23 : 25 : 4 | Case 1: 117.1858168 78.12387792Case 2: 107.29095604 85.8327648 |
题目类型:简单二分
算法分析:二分体育场的长,然后对于每一个长通过几何关系计算出体育场跑道的总周长。如果周长大于400,则向小的方向二分,反之,则向大的方向二分
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
#include <iostream> #include <fstream> #include <cstdio> #include <cmath> #include <iomanip> using namespace std; double len, wid; bool BinSearch (double val) { double ang = atan (wid / len); double R = val / 2 / cos (ang); double arc = 2 * 2 * ang * R; double temp = arc + val * 2; if (temp > 400) return false; return true; } int main() { // freopen ("aaa.txt", "r", stdin); int cases, flag = 1; scanf ("%d", &cases); while (cases--) { scanf ("%lf : %lf", &len, &wid); double left = 0, right = 800, mid; int i = 0, cnt = 66; while (i <= cnt) { mid = (left + right) / 2; if (BinSearch (mid)) left = mid; else right = mid; i++; } cout << "Case " << flag++ << ": " << fixed << setprecision (6) << left << " " << fixed << setprecision (6) << left * wid / len << endl; } return 0; } |
- « 上一篇:lightoj1054
- lightoj1062:下一篇 »