1 条题解

  • 0
    @ 2025-4-9 13:59:15

    题目分析

    题目要求计算运动员在长跑比赛中的配速(每公里用时),输入包括:

    1. 赛道分段数 nn总距离 distdist(单位:公里)
    2. 运动员编号 TT 及其在各分段的用时(H:MM:SS 格式)
    3. 若某分段未完成(标记为 -:--:--),则输出无效。

    算法思路

    1. 输入处理

      • 读取分段数 nn 和总距离 distdist
      • 对每个运动员:
        • 检查是否有未完成分段(-:--:--)。
        • 若全部完成,将各分段时间转换为秒数并累加,得到总时间 tottot
    2. 配速计算

      • 计算平均每公里用时(秒):ave=totdist\text{ave} = \frac{tot}{dist}
      • 四舍五入到整数秒:ans=ave+0.5\text{ans} = \lfloor \text{ave} + 0.5 \rfloor
      • 转换为 MM:SS 格式输出。
    3. 无效处理

      • 若存在未完成分段,输出 -
    #include "stack"
    #include "cstdio"
    #include "iostream"
    #include "cmath"
    #include "set"
    #include "sstream"
    #include "cctype"
    #include "string"
    #include "cstring"
    #include "algorithm"
    #include "queue"
    #include "map"
    using namespace std;
    #define LL long long
    #define inf 0x7ffffff
    #define pa pair<int,int>
    #define pi 3.1415926535897932384626433832795028841971
     
    const int M = 15;
     
    int main()
    {
    	char s[M];
    	int i, n, H, MM, SS, T, ans;
    	double dist, tot, ave;
    	bool flag;
    	scanf("%d%lf", &n, &dist);
    	while (~scanf("%d", &T))
    	{
    		tot = 0.0;
    		flag = true;
    		for (i = 0; i < n; i++)
    		{
    			scanf("%s", s);
    			if (!strcmp(s, "-:--:--"))
    			{
    				flag = false;
    			}
    			else
    			{
    				sscanf(s, "%d:%d:%d", &H, &MM, &SS);
    				tot += H*3600.0 + MM*60.0 + SS*1.0;
    			}
    		}
    		if (flag == false)
    		{
    			printf("%3d: -\n", T);
    		}
    		else
    		{
    			ave = tot / dist;
    			ans = floor(ave + 0.5);
    			printf("%3d: %d:%02d min/km\n", T, ans / 60, ans % 60);
    		}
    	}
    	return 0;
    }
     
    
    
    • 1

    信息

    ID
    1566
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者