Algoogle

Algorithm for Programming Contest

AOJ 1187 ICPC Ranking

Category: AOJ Tag: implementation

ICPC Ranking

問題概要


解法


解法はチームの情報を管理する構造体を作って
正解したらsolved+=1, penalty += m + (その問題のWA回数)*20
してソートする.
最後の出力は次がsolvedもpenaltyも同じだったら”=”を間に出力, それ以外は”,”を出力する.

コード


(1187.cpp) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
#define rep(i,a) for(int i = 0;i < (a); i++)
#define all(u) (u).begin(),(u).end()
#define pb push_back

using namespace std;

struct S{
    int id, solved, pena;
    S(int id, int solved, int pena):id(id),solved(solved),pena(pena){}
    bool operator < (const S &s) const{
        if(solved != s.solved) return solved > s.solved;
        if(pena != s.pena) return pena < s.pena;
        return id > s.id;
    }
    bool operator == (const S &s) const{
        return (solved == s.solved && pena == s.pena);
    }
};

int main(){
    int M, T, P, R;
    while(cin>>M>>T>>P>>R, M||T||P||R){
        vector<S> team;
        int failed[400][16] = {0};
        rep(i,T) team.pb(S(i+1,0,0));
        rep(i,R){
            int m, t, p, j;
            cin >> m >> t >> p >> j;
            t--;
            if(!j){
                team[t].solved++;
                team[t].pena += m + failed[t][p];
            }
            else failed[t][p] += 20;
        }
        sort(all(team));
        rep(i,T) cout << team[i].id << (i==T-1? "": team[i]==team[i+1]? "=": ",");
        cout << endl;
    }
    return 0;
}

Comments