HDU1036 Average is not Fast Enough!

本是古典 何须时尚 2022-06-09 13:12 232阅读 0赞

Problem Description

A relay is a race for two or more teams of runners. Each member of a team runs one section of the race. Your task is to help to evaluate the results of a relay race.

You have to process several teams. For each team you are given a list with the running times for every section of the race. You are to compute the average time per kilometer over the whole distance. That’s easy, isn’t it?
So if you like the fun and challenge competing at this contest, perhaps you like a relay race, too. Students from Ulm participated e.g. at the “SOLA” relay in Zurich, Switzerland. For more information visit http://www.sola.asvz.ethz.ch/ after the contest is over.

Input

The first line of the input specifies the number of sections n followed by the total distance of the relay d in kilometers. You may safely assume that 1 <= n <= 20 and 0.0 < d < 200.0. Every following line gives information about one team: the team number t (an integer, right-justified in a field of width 3) is followed by the n results for each section, separated by a single space. These running times are given in the format “h:mm:ss” with integer numbers for the hours, minutes and seconds, respectively. In the special case of a runner being disqualified, the running time will be denoted by “-:—:—“. Finally, the data on every line is terminated by a newline character. Input is terminated by EOF.

Output

For each team output exactly one line giving the team’s number t right aligned in a field of width 3, and the average time for this team rounded to whole seconds in the format “m:ss”. If at least one of the team’s runners has been disqualified, output “-“ instead. Adhere to the sample output for the exact format of presentation.

Sample Input

2 12.5

5 0:23:21 0:25:01

42 0:23:32 -:—:—

7 0:33:20 0:41:35

Sample Output

5: 3:52 min/km

42: -

7: 6:00 min/km

Code:

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdio.h>
  4. #include <cstdlib>
  5. #include <cstring>
  6. #include <cmath>
  7. #include <ctime>
  8. #include <ctype.h>
  9. using namespace std;
  10. int main()
  11. {
  12. int n,num;
  13. float d;
  14. char tim[8];
  15. scanf("%d%f",&n,&d);
  16. while(scanf("%d",&num)!=EOF)
  17. {
  18. float seconds=0;
  19. int flag=0;
  20. for(int i=0;i<n;i++)
  21. {
  22. scanf("%s",&tim);
  23. if(tim[0]=='-')
  24. flag=1;
  25. else
  26. seconds+=(tim[0]-'0')*3600+((tim[2]-'0')*10+tim[3]-'0')*60+(tim[5]-'0')*10+tim[6]-'0';
  27. }
  28. int k=seconds/d+0.5;
  29. if(flag)
  30. printf("%3d: -\n",num);
  31. else
  32. printf("%3d:%2d:%02d min/km\n",num,k/60,k%60);
  33. }
  34. return 0;
  35. }

发表评论

表情:
评论列表 (有 0 条评论,232人围观)

还没有评论,来说两句吧...

相关阅读

    相关 HDU 5353 Average

    思路: 找到一个非零的点,然后从左贪心地走一遍,然后从右贪心走一遍 贪心就是如果现在的数是大于零的数,则给下一位; 如果现在的数是小于零的数,则下一位给我。 比赛