Codeforces 659B Qualifying Contest【模拟,读题】

写这道题题解的目的就是纪念一下半个小时才读懂题。。。英文一多读一读就溜号。。。
读题时还时要静下心来。。。


题目链接:

http://codeforces.com/contest/659/problem/B

题意:

给定地区及来自相应地区的人的分数,每个地区选两个分数最高的人 参加区域赛,如果选出的两个人唯一,则输出名字,否则如果还需要进行下一次比赛,输出“?”。

分析:

不唯一的情况就是第二个人和第三个人的分数相同嘛。。。排个序找一下就好了。

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct Node{string s; int sc;};
Node node[maxn];
int num[maxn];
vector<Node>v[maxn];
bool cmp(Node a, Node b)
{
    return a.sc >b.sc;
}
int main (void)
{
    int n, m;
    cin>>n>>m;
    string s;
    int id, score;
    for(int i = 0; i <n; i++){
        cin>>s>>id>>score;
        node[i] = (Node){s, score};
        v[id].push_back(node[i]);
        num[id]++;
    }
    for(int i = 1; i <= m; i++){
        sort(v[i].begin(), v[i].end(), cmp);
        if(v[i].size() > 2 && v[i][2].sc == v[i][1].sc) cout<<"?"<<endl;
        else cout<<v[i][0].s<<' '<<v[i][1].s<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758684.html