首页 > 代码库 > HDU 3128 What is the air speed velocity…(数学)
HDU 3128 What is the air speed velocity…(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3128
Problem Description
What is the air speed velocity…
…of a fully laden swallow? This fearful question was posed to the intrepid band of Grail searchers.Their response of "African or European?" was partly correct.The air speed would most definitely depend on the sub-species of swallow. King Arthur, fearing more intense questioning in this vein,ordered his royal mathematicians to determine the air speed of a fully laden swallow - both African and European.
The mathematicians called upon the royal birders to capture a number of swallows of both types, lade them fully, and then release them from point A and time their arrival at point B.Since they didn‘t want to confuse their figures, the European and African swallows were each started from a different location, so that each group flew a different distance, but all swallows in the same group flew the same distance. They then asked the royal map-makers to determine the distance (measured in furlongs) between the two starting points and the finish point. Using 10 swallows of each type, the royal mathematicians would then compute the average air speed for each group.
However, the royal mathematicians were somewhat lazy. After gathering all the data, they decided it was MUCH too hard to do all those nasty calculations by hand. So, they quickly constructed a time machine and have come into the future to enlist your help: they need you to write a program to do the calculations, which they will then take back into the past with them. Thus the searchers of the Grail will be saved from certain doom, (should this dastardly question be posed again), and you will go down in history as a hero. (Well, maybe not history, since they are from the past, so maybe you‘ll go down in futurory?)
There‘s one tricky bit (you knew it was coming): the royal mathematicians cannot agree on exactly how the average should be calculated. Some believe that, for each group, one should add up all of the times and then divide the total distance covered by all the swallows of that type by the total time (this is method 1). Others are of the opinion that the average speed is determined by computing the speed for each swallow, summing those values and then dividing that total by the total number of swallows (this is method 2). Your program should compute the average both ways, to avoid a nasty falling out among the royal mathematicians.
The input provided by the royal mathematicians is somewhat disorganized - the two breeds‘times have been intermixed and they weren‘t too careful about capitalization. But each entry is on a separate line and marked with an ‘A‘ or ‘a‘ or ‘E‘ or ‘e‘ to aid in identification. Each line begins with this single letter, followed by a single space. The final datum on the line is the elapsed time the swallow flew, expressed in hours. Since the time-keeping of the era wasn‘t very accurate, this value is simply a real number (>0) with a single level of precision, such as 1.5 (one and a half hours), or 0.4 (four-tenths of an hour).
…of a fully laden swallow? This fearful question was posed to the intrepid band of Grail searchers.Their response of "African or European?" was partly correct.The air speed would most definitely depend on the sub-species of swallow. King Arthur, fearing more intense questioning in this vein,ordered his royal mathematicians to determine the air speed of a fully laden swallow - both African and European.
The mathematicians called upon the royal birders to capture a number of swallows of both types, lade them fully, and then release them from point A and time their arrival at point B.Since they didn‘t want to confuse their figures, the European and African swallows were each started from a different location, so that each group flew a different distance, but all swallows in the same group flew the same distance. They then asked the royal map-makers to determine the distance (measured in furlongs) between the two starting points and the finish point. Using 10 swallows of each type, the royal mathematicians would then compute the average air speed for each group.
However, the royal mathematicians were somewhat lazy. After gathering all the data, they decided it was MUCH too hard to do all those nasty calculations by hand. So, they quickly constructed a time machine and have come into the future to enlist your help: they need you to write a program to do the calculations, which they will then take back into the past with them. Thus the searchers of the Grail will be saved from certain doom, (should this dastardly question be posed again), and you will go down in history as a hero. (Well, maybe not history, since they are from the past, so maybe you‘ll go down in futurory?)
There‘s one tricky bit (you knew it was coming): the royal mathematicians cannot agree on exactly how the average should be calculated. Some believe that, for each group, one should add up all of the times and then divide the total distance covered by all the swallows of that type by the total time (this is method 1). Others are of the opinion that the average speed is determined by computing the speed for each swallow, summing those values and then dividing that total by the total number of swallows (this is method 2). Your program should compute the average both ways, to avoid a nasty falling out among the royal mathematicians.
The input provided by the royal mathematicians is somewhat disorganized - the two breeds‘times have been intermixed and they weren‘t too careful about capitalization. But each entry is on a separate line and marked with an ‘A‘ or ‘a‘ or ‘E‘ or ‘e‘ to aid in identification. Each line begins with this single letter, followed by a single space. The final datum on the line is the elapsed time the swallow flew, expressed in hours. Since the time-keeping of the era wasn‘t very accurate, this value is simply a real number (>0) with a single level of precision, such as 1.5 (one and a half hours), or 0.4 (four-tenths of an hour).
Input
The very first line of the input file will consist of 2 integers, both greater than 0, separated by a single space. The first integer is the distance the African swallows flew and the second integer is the distance the European swallows flew. Next come the times for the swallows (20 lines total: 10 for African, 10 for European - NOT in this order). Thus the input file has a total of 21 lines.
Output
The format for the output should be grouped by methods, with Method 1 being displayed first.
Each method will produce 3 lines of output:
The format for the data for each method is as follows:
See the Sample output section below for any clarifications you require.
Each method will produce 3 lines of output:
- Line 1: the name of the method (capitalized, with a digit identifying it), e.g. "Method 1"(the quotes are not part of your output.)
- Line 2: the speed of a fully-laden African swallow (expressed in furlongs per hour),e.g. "African: 3.00 furlongs per hour" (the quotes are not part of your output.)
- Line 3: the speed of a fully-laden European swallow (expressed in furlongs per hour),e.g. "European: 3.00 furlongs per hour" (the quotes are not part of your output.)
The format for the data for each method is as follows:
- The full name of the breed of swallow (capitalized), beginning with African
- A colon
- A single space
- The speed (to two digits of accuracy, with leading 0 for values < 1.0)
- A single space
- The phrase "furlongs per hour" (the quotes are not part of the output).
See the Sample output section below for any clarifications you require.
Sample Input
6 5 a 1.0 A 1.0 E 2.0 E 2.0 A 1.0 e 2.0 a 1.0 A 1.0 E 2.0 E 2.0 A 1.0 e 2.0 a 1.0 A 1.0 E 2.0 E 2.0 A 1.0 e 2.0 e 1.0 a 2.0
Sample Output
Method 1 African: 5.45 furlongs per hour European: 2.63 furlongs per hour Method 2 African: 5.70 furlongs per hour European: 2.75 furlongs per hour
Source
2006 ACM-ICPC Pacific Northwest Region
ps:
用两种不同的方法计算平均速度!
代码如下:
#include <cstdio> #include <cstring> int main() { double n, m; char s[17]; double time; while(~scanf("%lf%lf",&n,&m)) { double sum1 = 0; double sum2 = 0; double v1 = 0; double v2 = 0; for(int i = 0; i < 20; i++) { scanf("%s%lf",s,&time); if(s[0]=='A' || s[0]=='a') { sum1 += time; v1 += n/time; } else { sum2 += time; v2 += m/time; } } printf("Method 1\n"); printf("African: %.2lf furlongs per hour\n",n*10.0/sum1); printf("European: %.2lf furlongs per hour\n",m*10.0/sum2); printf("Method 2\n"); printf("African: %.2lf furlongs per hour\n",v1/10.0); printf("European: %.2lf furlongs per hour\n",v2/10.0); } return 0; }
HDU 3128 What is the air speed velocity…(数学)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。