hdu3040 Happy Girls 水题

本文详细介绍了如何通过排序算法解决实际问题,包括数据排序的基本原理、常见算法对比及优化策略,以及实例应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3040

水题,排个序就好了。

///2014.4.3 - 2014.4.5
///hdu3040

///203MS

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

struct Vote{
    int time;
    long long tel;
    int  num;
};

int N;
int girlGet[11];
int numOfVote;
Vote vote[50100];

void init(){
    memset(girlGet,0,sizeof(girlGet) );
    numOfVote = 0;

    int h,m,s;
    unsigned long long tel;
    int num;
    while( scanf("%d",&h)==1 ){
        scanf(":%d:%d %llu %d\n",&m,&s,&tel,&num);
        vote[numOfVote].time = h*3600 + m*60 + s ;
        vote[numOfVote].tel = tel;
        vote[numOfVote].num = num;
        numOfVote++;
    }
    scanf("#end\n");
}

bool cmp(Vote A,Vote B){
    if(A.tel > B.tel)
        return false;
    else if(A.tel < B.tel)
        return true;
    else
        return A.time < B.time;
}

int main()
{
    // freopen("in","r",stdin);
    // freopen("out","w",stdout);

    while( cin>>N ){
        init();
        sort(vote,vote+numOfVote,cmp);
        
        girlGet[ vote[0].num ]++;
        int ti  = vote[0].time;
        for(int i=1 ; i<numOfVote ; i++){
            if( vote[i].tel==vote[i-1].tel ){
                if( vote[i].time-ti >= 60 ){
                    ti = vote[i].time;
                    girlGet[ vote[i].num ]++;
                }
            }
            else{
                ti = vote[i].time;
                girlGet[ vote[i].num ]++;
            }
        }

        cout<<"The result is :"<<endl;
        for(int i=1 ; i<=N ; i++){
            printf("%02d : ",i );
            for(int j=0 ; j<girlGet[i] ; j++){
                printf("*");
            }
            cout<<endl;
        }
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值