Pro.ID10184 TitleCowcycles Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10184 AC4 Submit5 Ratio80.00% 时间&空间限制描述[note that some words are puns on cows.] Having made a fortune on Playbov magazine, Hugh Heifer has moved from his original field in the country to a fashionable yard in the suburbs. To visit fond pastoral memories, he wishes to cowmmute back to his old stomping grounds. Being environmentally minded, Hugh wishes to transport himself using his own power on a Cowcycle (a bicycle specially fitted for his neatly manicured hooves). Hugh weighs over a ton; as such, getting smoothly up to speed on traditional cowcycle gear sets is a bit challenging. Changing among some of the widely spaced gear ratios causes exertion that's hard on Hugh's heart. Help Hugh outfit his Cowcycle by choosing F (1 ≤ F ≤ 5) gears (sprockets) in the front and R (1 ≤ R ≤ 10) gears in the rear of his F×R speed cowcycle subject to these rules:
Calculate the mean and variance of a set of differences (xi in this formula) by the following formulae: 1 n Deduce and print the optimal sets of F front gears and R rear gears so that the variance is minimized (and the ratios span a factor of at least 3x). 输入The first line contains F and R, the numbers of front and rear gears. The second line contains four numbers: F1, F2 (25 ≤ F1 < F2 ≤ 80), R1, and R2 (5 ≤ R1 < R2 ≤ 40). All front gears from F1 through F2 are available; all rear gears from R1 through R2 are available. There will exist at least one legal set of gears. 输出Description [note that some words are puns on cows.] Having made a fortune on Playbov magazine, Hugh Heifer has moved from his original field in the country to a fashionable yard in the suburbs. To visit fond pastoral memories, he wishes to cowmmute back to his old stomping grounds. Being environmentally minded, Hugh wishes to transport himself using his own power on a Cowcycle (a bicycle specially fitted for his neatly manicured hooves). Hugh weighs over a ton; as such, getting smoothly up to speed on traditional cowcycle gear sets is a bit challenging. Changing among some of the widely spaced gear ratios causes exertion that's hard on Hugh's heart. Help Hugh outfit his Cowcycle by choosing F (1 ≤ F ≤ 5) gears (sprockets) in the front and R (1 ≤ R ≤ 10) gears in the rear of his F×R speed cowcycle subject to these rules:
Calculate the mean and variance of a set of differences (xi in this formula) by the following formulae: 1 n Deduce and print the optimal sets of F front gears and R rear gears so that the variance is minimized (and the ratios span a factor of at least 3x). Input The first line contains F and R, the numbers of front and rear gears. The second line contains four numbers: F1, F2 (25 ≤ F1 < F2 ≤ 80), R1, and R2 (5 ≤ R1 < R2 ≤ 40). All front gears from F1 through F2 are available; all rear gears from R1 through R2 are available. There will exist at least one legal set of gears. Output Display the number of teeth on the set of F chosen front gears, from smallest to largest, on the first line of output (separated by spaces). Display the number of teeth on the set of R chosen rear gears, from smallest to largest, on the second line of output. All gears have an integer number of teeth, of course. If multiple optimal answers exist, output the answer with the smallest front gear set (smallest first gear, or smallest second gear if first gears match, etc.). Likewise, if all first gears match, output the answer with the smallest rear gear set (similar rules to the front gear set). Sample Input 2 5 Sample Output 39 53 Hint The challenge in this problem is "reading the problem". Don't read further if you are working on that level of challenge. If the problem is just completely unclear to you, read in. The problem wants you to find "an optimal set of gear ratios" such that the spacing between the ratios is most uniform. Consider the test case above: 2 5 This specifies two front gears from the set 39..62; five rear gears from the set 12..28. The program must examine all possible pairs of 62-39+1=24 front gears and all possible quintuples from 28-12+1=17 rear gears. Combinatorically, The total number of possibilities is (24 take 2) times (17 take 5), which is 24!/22!/2! x 17!/5!/12! which is 656,880 possibilities (I think). For each of these possibilities, calculations like the following. This example considers in some sense the "first" case: front gears of 39 and 40, rear gears of 12, 13, 14, 15, and 16. First, calculate all the possible ratios: 39/12 = 3.25000000000000000000 Then, sort them: 39/16 = 2.43750000000000000000 Then, calculate the absolute value of the differences: 2.43750000000000000000 - 2.50000000000000000000 = 0.06250000000000000000 Then, calculate the mean and variance of the set of numbers on the right, above. The mean is (I think): 0.0995370370370370370366666. The variance is approximately 0.00129798488416722. Of course this set of gears is not valid, since it does not have a 3x span from highest gear to lowest. Find the set of gears that minimizes the variance and has a 3x or greater span. Source 样例输入2 5 样例输出39 53 提示The challenge in this problem is "reading the problem". Don't read further if you are working on that level of challenge. If the problem is just completely unclear to you, read in. The problem wants you to find "an optimal set of gear ratios" such that the spacing between the ratios is most uniform. Consider the test case above: 2 5 This specifies two front gears from the set 39..62; five rear gears from the set 12..28. The program must examine all possible pairs of 62-39+1=24 front gears and all possible quintuples from 28-12+1=17 rear gears. Combinatorically, The total number of possibilities is (24 take 2) times (17 take 5), which is 24!/22!/2! x 17!/5!/12! which is 656,880 possibilities (I think). For each of these possibilities, calculations like the following. This example considers in some sense the "first" case: front gears of 39 and 40, rear gears of 12, 13, 14, 15, and 16. First, calculate all the possible ratios: 39/12 = 3.25000000000000000000 Then, sort them: 39/16 = 2.43750000000000000000 Then, calculate the absolute value of the differences: 2.43750000000000000000 - 2.50000000000000000000 = 0.06250000000000000000 Then, calculate the mean and variance of the set of numbers on the right, above. The mean is (I think): 0.0995370370370370370366666. The variance is approximately 0.00129798488416722. Of course this set of gears is not valid, since it does not have a 3x span from highest gear to lowest. Find the set of gears that minimizes the variance and has a 3x or greater span. |