1830: 【USACO】Race Results(比赛结果)

25 篇文章 0 订阅
2 篇文章 0 订阅

1830: 【USACO】Race Results(比赛结果)

时间限制: 1.000 Sec  内存限制: 64 MB
提交: 324  解决: 204
[命题人:][下载数据: 70]

提交状态报告

题目描述

The herd has run its first marathon! The N (1 <= N <= 5,000) times have been posted in the form of Hours (0 <= Hours <= 99), Minutes (0 <= Minutes <= 59), and Seconds (0 <= Seconds <= 59). Bessie must sort them (by Hours, Minutes, and Seconds) into ascending order, smallest times first. Consider a simple example with times from a smaller herd of just 3 cows (note that cows do not run 26.2 miles so very quickly): 11:20:20 11:15:12 14:20:14 The proper sorting result is: 11:15:12 11:20:20 14:20:14
/*
奶牛们成功的举行了第一届马拉松大赛!!! 这里有N(1<=N<=5000)只奶牛的成绩,每一个成绩用三个整数表示,即小时数(0 <= 小时数 <= 99)分钟数(0 <= 分钟数 <= 59)和秒数(0 <= 秒数 <= 59).贝茜必须将它们排序(小时,分钟,秒数都要参考),最后的结果应该一个升序的,也就是说,用时最少的在最前面.
看这么一个例子,这里有3只奶牛的成绩(记录显示奶牛们在跑26.2英里时也不是很快^_^):
11:20:20
11:15:12
14:20:14
最后排序的结果应该是:
11:15:12
11:20:20
14:20:14
*/

输入

* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 contains cow i's time as three space-separated integers: Hours, Minutes, Seconds
/*
第1行:一个整数N
第2..N+1行:每一行有三个整数,第i+1行描述的是奶牛i的成绩.
*/

输出

* Lines 1..N: Each line contains a cow's time as three space-separated integers
/*
有N行,每一行三个整数.这是排序后的结果.
*/

样例

输入  复制

3 11 20 20 11 15 12 14 20 14

输出  复制

11 15 12 11 20 20 14 20 14

来源/分类

USACO 2010 November Bronze 

AC

#include<iostream>
#include<algorithm>
using namespace std;
int h[5001],m[5001],s[5001],sum[5001];
void swap(int &x,int &y) {
    int t=x;x=y;y=t;
}
void kp(int a,int b) {
    int i=a,j=b,mid=sum[(a+b)/2];
    while(i<=j) {
        while(sum[i]<mid)i++;
        while(sum[j]>mid)j--;
        if(i<=j) {
            swap(sum[i],sum[j]);
            swap(h[i],h[j]);
            swap(m[i],m[j]);
            swap(s[i],s[j]);
            i++;j--;
        }
    }
    if(a<j)kp(a,j);
    if(i<b)kp(i,b);
}
int main() {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>h[i]>>m[i]>>s[i];
        sum[i]=h[i]*3600+m[i]*60+s[i];
    }
    kp(1,n);
    for(int i=1;i<=n;i++)
    cout<<h[i]<<" "<<m[i]<<" "<<s[i]<<"\n";
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值