考察多路排序,可以自己排,也可以用一个堆,堆本身就很适合多路排序
#include<deque>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct node
{
char name[12];
int net,age;
bool operator<(const node&x)const
{
if(x.net!=net)return net>x.net;
else return strcmp(name,x.name)<0;
}
bool operator>(const node&x)const
{
if(x.net!=net)return net<x.net;
else if(x.age!=age)return age>x.age;
return strcmp(name,x.name)>0;
}
};
using DN=deque<node>;
int main()
{
int n,m;
cin>>n>>m;
DN sr[202],so(n);
for(int i=0;i<n;++i)
scanf("%s%d%d",so[i].name,&so[i].age,&so[i].net);
sort(so.begin(),so.end());
for(auto&x:so) sr[x.age].push_back(x);
for(int be,en,cnt,i=0;i<m;++i)
{
cin>>cnt>>be>>en;
printf("Case #%d:\n",i+1);
priority_queue<node,deque<node>,greater<node>>pq;
for_each(sr+be, sr+en+1, [&](DN&x){ if(x.size()) pq.push(x[0]); } );
if(pq.empty()) printf("None\n");
else
{
int cur[202]={0};
for(int times=0;times<cnt;++times)
if(pq.size())
{
node x=pq.top();
printf("%s %d %d\n",x.name,x.age,x.net);
cur[x.age]++;
pq.pop();
if(cur[x.age]<sr[x.age].size())
pq.push(sr[x.age][cur[x.age]]);
}
}
}
return 0;
}