题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1434
中文题,不解释题目意思了。
这个就是优先队列的模拟题。
自定义优先队列里面元素的排序规则要会。
不多说了,直接上代码:
下面是AC代码:
#include<iostream>
#include<queue>
using namespace std;
const int maxn=10005;
struct node
{
string name;
int rp;
friend bool operator<(node a,node b)
{
if(a.rp!=b.rp) return a.rp>b.rp;//第一关键字,如果人品不相等,这样写就是说人品差的会排在队首(堆顶)
return a.name<b.name;//第二关键字,如果人品相等,那么姓名字典序大的队首(堆顶)
}
};
int main()
{
int n,m;
cin.sync_with_stdio(false);
while(cin>>n>>m)
{
priority_queue<node>q[maxn];
node t;
for(int i=1;i<=n;i++)
{
int cnt,rp,id;
string name;
cin>>cnt;
while(cnt--)
{
cin>>name>>rp;
t.name=name;
t.rp=rp;
q[i].push(t);
}
}
while(m--)
{
string s,name;
int rp,xi,xj;
cin>>s;
if(s=="GETON")
{
cin>>xi>>name>>rp;
t.name=name;
t.rp=rp;
q[xi].push(t);
}
else if(s=="JOIN")
{
cin>>xi>>xj;
while(q[xj].size())
{
t=q[xj].top();q[xj].pop();
q[xi].push(t);
}
}
else
{
cin>>xi;
cout<<q[xi].top().name<<endl;
q[xi].pop();
}
}
}
return 0;
}