LA 3135 (优先队列) Argus
将多个有序表合并成一个有序表就是多路归并问题,可用优先队列来解决。
1 #include <cstdio> 2 #include <queue> 3 using namespace std; 4 5 const int maxn = 1000 + 10; 6 7 struct Node 8 { 9 int time, period, num; 10 bool operator < (const Node& rhs) const 11 { 12 return time > rhs.time || (time == rhs.time && num > rhs.num); 13 } 14 }a[maxn]; 15 16 char s[100]; 17 18 int main() 19 { 20 //freopen("in.txt", "r", stdin); 21 22 priority_queue<Node> Q; 23 while(scanf("%s", s) == 1 && s[0] != '#') 24 { 25 Node t; 26 scanf("%d%d", &t.num, &t.period); 27 t.time = t.period; 28 Q.push(t); 29 } 30 int k; 31 scanf("%d", &k); 32 while(k--) 33 { 34 Node t = Q.top(); Q.pop(); 35 printf("%d\n", t.num); 36 t.time += t.period; 37 Q.push(t); 38 } 39 40 return 0; 41 }