Title: Click here
Test instructions
Invite K friends, each friend with a gift value of different, M-times open, each door to a certain number of P (if the number of people less than P, all in) come in, when the end of everyone will also open a door, let not come in the people come in, each time is a gift of high value advanced. Finally, the number of Q is given, which indicates the name of the person to output the first NI to come in.
Analysis:
Priority queue issues. Note that the comparison function for the priority queue is the team order,
1#include <iostream>2#include <cstdio>3#include <queue>4#include <cstring>5#include <algorithm>6 7 using namespacestd;8 Const intM =150005;9 Ten structNode {//Save Visitor Information One Charname[205]; A intVal; - intID; - BOOL operator< (ConstNode x)Const{//Sort Note-the order of the queues in the priority queue the if(val = = x.val)returnID >x.id; - returnVal <X.val; - } - }node[m]; + structTime {//Save Open Door information--to sort--the data given may not be in order - intT, p; + BOOL operator< (ConstTime X)Const{returnT <x.t;} A }time[m]; at - intK, M, Q; - Charstr[m][205];//Answer - - voidsolve () { -scanf"%d%d%d", &k, &m, &q); in for(intI=1; i<=k; i++ ) { -scanf"%s%d", Node[i].name, &node[i].val); toNode[i].id =i; + } - for(intI=0; i<m; i++ ) thescanf"%d%d", &TIME[I].T, &TIME[I].P); *Sort (time, time+m);//sort the opening information $Priority_queue<node>Q;Panax Notoginseng intOrder =0; - intLast =0; the for(intI=0; i<m; i++ ) { + intT, p; t = time[i].t; p =TIME[I].P; A for(inti=last+1; i<=t; i++ ) { the Q.push (Node[i]); + } - for(intI=0; i<p; i++ ) { $ if(Q.empty ()) Break;//Note that the number of people outside the door is more than P-hour-the queue is directly terminated-or re- $Node nd =Q.top (); Q.pop (); -order++; - strcpy (Str[order], nd.name); the } -Last =T;Wuyi } the for(inti=last+1; i<=k; i++)//I open the door once again after opening the door. - Q.push (Node[i]); Wu while( !Q.empty ()) { -Node nd =Q.top (); Q.pop (); Aboutorder++; $ strcpy (Str[order], nd.name); - } - BOOLFO =false;//output Format - for(intI=1; i<=q; i++ ) { A intS scanf"%d", &s); + if(FO) printf ("%s", Str[s]); the Else{printf ("%s", Str[s]); FO =true; } - } $printf"\ n"); the } the the intMain () { the intT scanf"%d", &t); - while(t-- ) { in solve (); the } the return 0; About}
HDU OJ 5437 Alisha ' s Party 2015online A