HDU 3128 what is the air speed velocity... (Mathematics)

Source: Internet
Author: User

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 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 wowould 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 wowould 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, (shocould 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 shoshould be calculated. some believe that, for each group, one shoshould 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 shocould 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 '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 ).
Inputthe 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.
Outputthe format for the output shocould be grouped by methods, with method 1 being displayed first.
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 5a 1.0A 1.0E 2.0E 2.0A 1.0e 2.0a 1.0A 1.0E 2.0E 2.0A 1.0e 2.0a 1.0A 1.0E 2.0E 2.0A 1.0e 2.0e 1.0a 2.0
 
Sample output
Method 1African: 5.45 furlongs per hourEuropean: 2.63 furlongs per hourMethod 2African: 5.70 furlongs per hourEuropean: 2.75 furlongs per hour
 
Source2006 ACM-ICPC Pacific Northwest Region

PS:

Calculate the average speed in two different ways!

The Code is as follows:

#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... (Mathematics)

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.