HRBUST 1313 火影忍者之~静音

优先队列。

每次将$n$个人压入优先队列,取出$5$个,最后排序。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<iostream>
using namespace std;

int m,n;
struct X
{
    string name;
    int A,B;

    X(string Name,int AA,int BB)
    {
        name = Name;
        A=AA;
        B=BB;
    }

    bool operator < (const X &a) const {
        if(A!=a.A) return A<a.A;
        return name>a.name;
    }
};

struct Y
{
    string name;
    int A,B;
}t[10010];

bool cmp2(Y a,Y b)
{
    if(a.B!=b.B) return a.B>b.B;
    return a.name<b.name;
}

int main()
{
    while(~scanf("%d%d",&m,&n))
    {
        priority_queue<X>Q;
        int sz=0;
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                string str; int AA,BB;
                cin>>str;
                scanf("%d",&AA);
                scanf("%d",&BB);
                Q.push(X(str,AA,BB));
            }

            for(int j=0;j<5;j++)
            {
                X TOP = Q.top(); Q.pop();
                t[sz].name = TOP.name;
                t[sz].A = TOP.A;
                t[sz].B = TOP.B;

                sz++;
            }
        }

        sort(t,t+5*m,cmp2);
        for(int i=0;i<5;i++) cout<<t[i].name<<endl;

    }
    return 0;
}

 

posted @ 2017-03-08 11:51  Fighting_Heart  阅读(739)  评论(0编辑  收藏  举报