uvalive 3135 Argus priority_queue
用优先队列维护每个时间点优先级最高的元素。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<stack> 5 #include<queue> 6 #include<vector> 7 #include<map> 8 using namespace std; 9 int n,m; 10 11 struct Item 12 { 13 int Qnum,Period,Time; 14 bool operator<(const Item &a) const 15 { 16 return Time>a.Time||(Time==a.Time&&Qnum>a.Qnum); 17 } 18 }; 19 20 int main() 21 { 22 priority_queue<Item>pq; 23 char s[20]; 24 while(scanf("%s",s)&&s[0]!='#') 25 { 26 Item item; 27 scanf("%d%d",&item.Qnum,&item.Period); 28 item.Time=item.Period; 29 pq.push(item); 30 } 31 int k; 32 scanf("%d",&k); 33 while(k--) 34 { 35 Item r=pq.top(); 36 pq.pop(); 37 printf("%d\n",r.Qnum); 38 r.Time+=r.Period; 39 pq.push(r); 40 } 41 return 0; 42 }