Argus UVALive - 3135(优先队列 水题一道)

有一系列的事件,它每Period秒钟就会产生编号为qNum的事件,你的任务是模拟出前k个事件,如果多个事件同时发生,先处理qNum小的事件

今天再看看数据结构。。

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff; struct node
{
int value, time, T;
bool operator < (const node& a) const {
return time > a.time || (time == a.time && value > a.value);
}
}; int main()
{
priority_queue<node> q;
char s[];
while(scanf("%s", s) && s[] != '#')
{
node e;
scanf("%d%d", &e.value, &e.T);
e.time = e.T;
q.push(e);
}
int k;
cin>> k;
while(k--)
{
node e = q.top();
q.pop();
cout<< e.value <<endl;
e.time += e.T;
q.push(e);
} return ;
}
上一篇:探秘 flex 上下文中神奇的自动 margin


下一篇:CodeForces 342B Xenia and Spies (水题模拟,贪心)