Topic Link: Click to enter
Just test instructions more difficult to understand, after reading the problem can be fully used in priority queue water past. The first priority rule for learning to customize a priority queue is to overload the < operator in the struct.
The code is as follows:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace STD;typedef structnode{intId,num;intT/// Custom Priority queue priority by overloading < operator friend BOOL operator< (node N1,node n2) {if(N1.num==n2.num)returnn1.id>n2.id;returnn1.num>n2.num; }}p; P p1,p2;priority_queue<p>q;intMain () {Charstr[ -];intb;//freopen ("In.txt", "R", stdin); while(scanf('%s ', str)) {if(strcmp(STR,"#")==0) Break;scanf("%d%d", &p1.id,&p1.num); P1.t=p1.num; Q.push (p1); }intKscanf("%d", &k); while(k--) {p2=q.top (); Q.pop ();printf("%d\n", p2.id); p2.num+=p2.t; Q.push (p2); }return 0;}
Uvalive 3135--argus+ precedence rules for custom priority queues