Codeforces 19A World Football Cup 【模拟】

本文详细解读了Codeforces平台上的19A World Football Cup问题,包括比赛规则、得分机制、排名算法及AC代码实现,提供了解决此类问题的深入理解与实践案例。

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

题目链接: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|1
using 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值