Codeforces Round #346 (Div. 2) B - Qualifying Contest 优先队列

来源:互联网 发布:java多线程 单例 编辑:程序博客网 时间:2024/05/22 12:39

题意:n个人,m个地区,每个地区要选出2个最高分的人,如果第三高分和第二高分一样分数,那么输出“?”


思路:直接用优先队列模拟


题目链接:http://codeforces.com/contest/659/problem/B


#include <bits/stdc++.h>using namespace std;struct node{    string name;    int num;    bool operator < (const node &rhs) const    {        return rhs.num > num;//按num排序    }};priority_queue<node> q[10005];//开一个优先队列数组int n, m, k, x;string name;node e, f, g;int main(){    cin>>n>>m;    for(int i=1; i<=m; i++)        while(!q[i].empty()) q[i].pop();    for(int i=0; i<n; i++)    {        cin>>name>>k>>x;        f.name = name, f.num = x;        q[k].push(f);    }    int cnt = 0;    for(int i=1; i<=m; i++)    {        cnt = 0;        while(!q[i].empty())        {            if(cnt == 0)            {                cnt++;                e = q[i].top();                q[i].pop();            }            else if(cnt == 1)            {                cnt++;                f = q[i].top();                q[i].pop();            }            else if(cnt == 2)            {                cnt++;                g = q[i].top();                q[i].pop();            }            else if(cnt == 3)                break;        }        if(cnt == 3)        {            if(f.num == g.num)                puts("?");            else                printf("%s %s\n", e.name.c_str(), f.name.c_str());//string的printf输出        }        else        {            printf("%s %s\n",e.name.c_str(), f.name.c_str());        }    }    return 0;}


0 0
原创粉丝点击