UVa 1203 - Argus
传送门
题意
给一个事件标号和发生周期,求前k个事件的标号
思路
用优先队列取前k个元素
代码
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 10000 + 5;
const int INF = 0x3f3f3f3f;
struct EVT
{
int num, tm, p;
bool operator < (const EVT &a) const
{
if (tm != a.tm)
return tm > a.tm;
return num > a.num;
}
};
priority_queue<EVT> pqu;
int main()
{
//freopen("input.txt", "r", stdin);
string str;
int num, tm, k, i, j;
EVT tmp;
while (cin >> str && str != "#")
{
cin >> tmp.num >> tmp.p;
tmp.tm = tmp.p;
pqu.push(tmp);
}
scanf("%d", &k);
for (i = 0; i < k; i++)
{
EVT t = pqu.top();
pqu.pop();
printf("%d\n", t.num);
t.tm += t.p;
pqu.push(t);
}
return 0;
}