Happy Train
Time limit:20000/10000 MS (java/others) Memory limit:131070/65535 K (java/others) total submission (s): 2169 Accept Ed Submission (s): 672
Problem description A group of happy train from Hangzhou to the happy Terminal-Wenzhou, as the chief conductor of the Linle have some strange hobby.
He would record all the passenger's names (name) and their character values (RP), according to these sort them, and occasionally from a train to play the most bad character (RP value of the lowest) of a person, when two people are as bad as the character, he will kick out the name of the nasty person (Linle think in dictionary order, The more people who are in the back, the worse the name is.
Of course, because of the need for the train, he also occasionally issued a number of orders, such as getting a passenger to the car, merging a two train and so on.
Linle's last secretary was fired for not being able to execute his orders efficiently, he is now looking for a new secretary, can you do it? (No men, very generous ~ ~ ~)
Input contains multiple sets of tests, please handle to the end of the file. For each set of tests, the first row contains two integers n, m, representing a total of n (n<=10000) trains, performing M (m<=10000) operations. Next there is an N (counting from 1) train information, each train has a number XI (1 <= XI <= 100), indicating that the train has XI passengers, followed by Xi passenger information, each passenger contains the name (20 characters, not including the blank character) and character (0<= RP <=30000). Then there is the M-line operation information, a total of 3 operations, respectively,
Geton XI name RP indicates that there is a character named name for the RP person aboard the first XI train
JOIN XI XJ represents the merger of the first XJ train to the Xi train
Getout Xi says a man of the worst character is kicked out of the first XI train
The test data ensures that each operation is legal, that the trains that have been merged into other trains are not merged, and that no passengers are kicked out of an empty train
Output for each getout command, outputs the name of the person to be kicked out
Sample Input3 52xhd 0zl 128600 1ll 21Ignatius 3GETOUT 1JOIN 1 2GETOUT 1GETON 3 HoHo 2GETOUT 3
Sample Outputxhdzlhoho
HintHuge input, scanf is recommended.
Priority queue; According to the test instructions water a water is good;
Code:
#include <iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<queue>using namespacestd;Const intMAXN =10010;structnode{Charnm[ +]; intRP; FriendBOOL operator<(Node A,node b) {if(A.RP! = B.RP)returnA.RP >B.RP; Else { if(strcmp (A.NM,B.NM) <0)return 1; Else return 0; }}};p riority_queue<Node>Q[MAXN];intMain () {intn,m,x; while(~SCANF ("%d%d",&n,&M)) {Node A; for(inti =1; I <= n;i++){ while(!q[i].empty ()) Q[i].pop (); scanf ("%d",&x); while(x--) {scanf ("%s%d",a.nm,&A.RP); Q[i].push (a); //printf ("***%s\n", Q[i].top ()); } } //printf ("***%s\n", Q[1].top ()); Chars[Ten]; intXI,XJ; while(m--) {scanf ("%s", s); if(strcmp (s),"Geton") ==0) {scanf ("%d%s%d",&xi,a.nm,&A.RP); Q[xi].push (a); } Else if(strcmp (s),"JOIN") ==0) {scanf ("%d%d",&xi,&XJ); while(!Q[xj].empty ()) {Q[xi].push (Q[xj].top ()); Q[xj].pop (); } } Else if(strcmp (s),"getout") ==0) {scanf ("%d",&XI); printf ("%s\n", Q[xi].top (). Nm); Q[xi].pop (); } } } return 0;}
Happy Train (priority queue simulation)