Codeforces 19A World Football Cup 【模拟】

来源:互联网 发布:苹果5s数据开关快捷键 编辑:程序博客网 时间:2024/05/16 04:52

题目链接:Codeforces 19A World Football Cup

题意:有n支队伍打n(n1)/2比赛,赢一场获得3分,平局得1分,输一局得0分。排名规则
一、按总分;
二、按进球数 - 被进球数;
三、按进球数;
均按降序。
最后按字典序输出前n/2支队伍。

AC代码:

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#include <stack>#define PI acos(-1.0)#define CLR(a, b) memset(a, (b), sizeof(a))#define fi first#define se second#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 50*50+10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;void getmax(int &a, int b) {a = max(a, b); }void getmin(int &a, int b) {a = min(a, b); }void add(LL &x, LL y) { x += y; x %= MOD; }struct Node {    string name;    int total;    int win, loss;};Node num[MAXN];bool cmp(Node a, Node b) {    if(a.total != b.total) return a.total > b.total;    if(a.win - a.loss != b.win - b.loss)        return a.win - a.loss > b.win - b.loss;    return a.win > b.win;}map<string, int> fp;string winner[MAXN];int main(){    int n; cin >> n; fp.clear();    for(int i = 1; i <= n; i++) {        cin >> num[i].name;        fp[num[i].name] = i;        num[i].total = num[i].win = num[i].loss = 0;    }    for(int i = 1; i <= n * (n-1) / 2; i++)    {        string a, b;        cin >> a >> b;        string team1, team2;        team1 = team2 = "";        int score1, score2;        score1 = score2 = 0;        int j = 0;        for(; j < a.size(); j++) {            if(a[j] == '-') break;            team1 += a[j];        }        j++;        for(; j < a.size(); j++)            team2 += a[j];        j = 0;        for(; j < b.size(); j++) {            if(b[j] == ':') break;            score1 = score1 * 10 + (b[j] - '0');        }        j++;        for(; j < b.size(); j++)            score2 = score2 * 10 + (b[j] - '0');        //cout << team1 << score1 << team2 << score2 << endl;        int s = fp[team1];        int t = fp[team2];        int snum, tnum;        if(score1 > score2) {            snum = 3;            tnum = 0;        }        else if(score1 < score2) {            snum = 0;            tnum = 3;        }        else snum = tnum = 1;        num[s].total += snum;        num[t].total += tnum;        num[s].win += score1;        num[s].loss += score2;        num[t].win += score2;        num[t].loss += score1;    }    sort(num+1, num+n+1, cmp);    for(int i = 1; i <= n/2; i++) {        winner[i] = "";        winner[i] += num[i].name;    }    sort(winner+1, winner+n/2+1);    for(int i = 1; i <= n / 2; i++)        cout << winner[i] << endl;    return 0;}
0 0
原创粉丝点击