Application of Priority queue
#include <iostream> #include <cstdio> #include <cstring> #include <queue>using namespaceStd;#define MAXN 10010structNode{String name;intRp;friendBOOLoperator< (Node A,Node b) {if(A.Rp !=B.Rp)returnA.Rp>B.Rp;Else returnA.Name<B.Name; }};Priority_queue<Node>Que[Maxn];intMain(){intN,M; while(~scanf("%d%d",&N,&M)) {Node tmp; for(intI =1;I<=N;I++) {intK;scanf("%d",&K); while(!Que[I].Empty())Que[I].Pop(); while(K--) {Cin>>Tmp.Name>>Tmp.Rp;Que[I].Push(Tmp); } } while(M--) {CharOp[ -];scanf('%s ',Op);if(!strcmp(Op,"Geton")) {intId;scanf("%d",&Id);Cin>>Tmp.Name>>Tmp.Rp;Que[Id].Push(Tmp); }else if(!strcmp(Op,"JOIN")) {intI1,I2;scanf("%d%d",&I1,&I2); while(!Que[I2].Empty()) {Tmp =Que[I2].Top();Que[I2].Pop();Que[I1].Push(Tmp); } }Else {intId;scanf("%d",&Id);Tmp =Que[Id].Top();Que[Id].Pop();cout<<Tmp.Name<<Endl; } } }return0;}
HDU 1434 Happy Train