http://poj.org/problem?id=2051
数据结构,优先队列
1 #include <stdio.h> 2 #include <string.h> 3 #include <queue> 4 5 using namespace std; 6 7 priority_queue<pair<int, int> > q; 8 9 int main() 10 { 11 char s[12] = "\0"; 12 int i, n, id, t[3003]; 13 pair<int, int> pair1; 14 for(i=1; scanf("%s", s), strcmp(s, "#"); i++) 15 { 16 memset(s, 0, sizeof(s)); 17 scanf("%d", &id); 18 scanf("%d%*c", t+id); 19 q.push(make_pair(-t[id], -id)); 20 } 21 scanf("%d", &n); 22 while(n --) 23 { 24 pair1 = q.top(); 25 q.pop(); 26 printf("%d\n", -pair1.second); 27 q.push(make_pair(pair1.first - t[-pair1.second], pair1.second)); 28 } 29 return 0; 30 }