zoukankan      html  css  js  c++  java
  • Aoj 418 ACM 排名

    复杂模拟,注意如果解题数目和解题总时间是一样的情况下两个人的名次是一样的。人的名次等于比他做得好的人数+1

    还有时间如果不足10要补零

    #include <iostream>
    #include <sstream>
    #include <string>
    #include <map>
    #include <set>
    #include <vector>
    #include <algorithm>
     
    using namespace std;
     
    struct time {
        int h,m,s;
        time(int hh,int mm,int ss):h(hh),m(mm),s(ss){};
        time():h(0),m(0),s(0){};
        string tostr() {
            ostringstream sout;
            sout << h << ":";
            if(m < 10) sout << "0"; sout << m << ":";
            if(s < 10) sout << "0"; sout << s;
            return sout.str();
        };
        time operator+=(time a) {
            s += a.s; m += a.m; h += a.h;
            if(s > 59) {
                m += s / 60;
                s %= 60;
            }
            if(m > 59) {
                h += m / 60;
                m %= 60;
            }
            return *this;
        }
    };
     
    time operator+(time a,time b) {
        return a += b;
    }
     
    bool operator<(time a,time b) {
        if(a.h != b.h) return a.h < b.h;
        if(a.m != b.m) return a.m < b.m;
        if(a.s != b.s) return a.s < b.s;
        return false;
    }
     
    bool operator!=(time a,time b) {
        return (a.h != b.h) || (a.m != b.m) || (a.s != b.s);
    }
     
    struct person {
        string name;
        time total;
        vector<bool> solved;
        vector<time> punish;
        int totalsolved;
        person(): name(""),solved(27,false),punish(27),totalsolved(0) {};
    };
     
    bool cmp(person a,person b) {
        if(a.totalsolved != b.totalsolved) return a.totalsolved > b.totalsolved;
        if(a.total != b.total) return a.total < b.total;
        return a.name < b.name;
    }
     
    map<string,person> all;
    vector<person> personlist;
    time punishtime(0,20,0);
     
    void process(string& line) {
        istringstream sin(line);
        string name,sta;
        char pid,tmp;
        int h,m,s,pnum;
        sin >> name >> pid >> h >> tmp >> m >> tmp >> s >> sta;
        time nowtime(h,m,s);
        pnum = pid - 'A';
        person &now = all[name];
        if(now.name == "") now.name = name;
        if(now.solved[pnum] == true) return;
        if(sta == "Accepted") {
            now.solved[pnum] = true;
            now.total += (nowtime + now.punish[pnum]);
            now.totalsolved++;
        } else now.punish[pnum] += punishtime;
    }
     
    void work() {
        string line;
        while(getline(cin,line)) process(line);
        for(map<string,person>::iterator iter = all.begin();iter != all.end();++iter) personlist.push_back(iter->second);
        sort(personlist.begin(),personlist.end(),cmp);
        int nowrank = 1;
        for(vector<person>::iterator iter = personlist.begin();iter != personlist.end();++iter) {
            if(iter != personlist.begin() && (iter->totalsolved != (iter - 1)->totalsolved || iter->total != (iter - 1)->total)) nowrank = (int)(iter - personlist.begin() + 1);
            if(iter->totalsolved == 0) cout << "- ";
            else cout << nowrank << " ";
            cout << iter->name << " " << iter->totalsolved << " " << iter->total.tostr() << endl;
        }
    }
     
    int main() {
        work();
        return 0;
    }
     
     
  • 相关阅读:
    组原——④存储器4
    sdk和api的区别
    转载:直播测试
    生成短链接
    H5调原生
    Android Intent 启动方法和启动Action大全
    ps和top的区别
    安卓知识点
    正则基础之——捕获组(capture group)
    正则基础之——反向引用
  • 原文地址:https://www.cnblogs.com/rolight/p/3484273.html
Copyright © 2011-2022 走看看