zoukankan      html  css  js  c++  java
  • 1095 Cars on Campus

    link

    #include <bits/stdc++.h>
    # define LL long long
    using namespace std;
    
    int gettime(int hh, int mm, int ss){
        return hh*3600+mm*60+ss;
    }
    
    struct Cartimes{
        int time;
        int flag;
        Cartimes(int t, int f):time{t},flag{f}{}
    };
    
    int main(){
        int N;
        int K;
        cin>>N>>K;
        unordered_map<string,vector<Cartimes>> mp;
        while(N--){
            string car;
            int hh,mm,ss;
            cin>>car;
            scanf("%d:%d:%d", &hh,&mm,&ss);
            string type;
            cin>>type;
            int time=gettime(hh,mm,ss);
            mp[car].push_back(Cartimes(time,type=="in"?1:-1));
        }
        for(auto& m:mp){
            sort(m.second.begin(),m.second.end(),[](Cartimes n1, Cartimes n2){
                return n1.time<n2.time;
            });
        }
        vector<Cartimes> carinterval;
        int maxtime=0;
        vector<string> res;
        for(auto& m:mp){
            string car=m.first;
            auto nodes=m.second;
            int totaltime=0;
            int in=-1;
            int out=0;
            for(auto n:nodes){
                if(n.flag==1){
                    in=n.time;
                }else{
                    if(in!=-1){
                        out=n.time;
                        int t=out-in;
                        totaltime+=t;
                        carinterval.push_back({in,1});
                        carinterval.push_back({out,-1});
                        in=-1;
                    }
                };
            }
            if(totaltime==maxtime){
                res.push_back(car);
            }else if(totaltime>maxtime){
                maxtime=totaltime;
                res.clear();
                res.push_back(car);
            }
        }
        sort(carinterval.begin(), carinterval.end(), [](Cartimes c1, Cartimes c2){
            return c1.time<c2.time;
        });
        int records=carinterval.size();
        vector<int> cnt(records);
        cnt[0]=1;
        for(int i=1;i<records;i++){
            cnt[i]=cnt[i-1]+carinterval[i].flag;
        }
    
        int idx=0;
        while(K--){
            int hh,mm,ss;
            scanf("%d:%d:%d", &hh, &mm, &ss);
            int q=gettime(hh,mm,ss);
            while(idx<records && q>=carinterval[idx].time) idx++;
            printf("%d
    ", idx==0?0:cnt[idx-1]);
        }
        int second=maxtime%60;
        int minute=maxtime/60%60;
        int hour=maxtime/60/60;
        sort(res.begin(),res.end());
        for(int i=0;i<res.size();i++){
            if(i>0) printf(" ");
            printf("%s", res[i].c_str());
        }
        printf(" %02d:%02d:%02d", hour,minute,second);
        return 0;
    }
  • 相关阅读:
    DBCC 常用命令
    查看数据库备份情况
    identity 列自动增长问题(SQL Server 2012 Auto Identity Column Value Jump Issue)
    job相关脚本
    Ad hoc update to system catalogs is not supported
    数据库加密&证书创建
    sp_MSforeachdb&sp_MSforeachtable&sp_MSforeachobject&查看某个对象的依赖对象
    session 学习
    Eclipse Python Djando 环境配置
    MySQL 日志文件与相关参数
  • 原文地址:https://www.cnblogs.com/FEIIEF/p/12656743.html
Copyright © 2011-2022 走看看