标签:style http color os io re c 代码
题意:给定一些注册命令,表示每隔时间t,执行一次编号num的指令,注册命令结束后,给定k,输出前k个执行顺序
思路:用优先队列去搞,任务时间作为优先级,每次一个任务出队后,在把它下次执行作为一个新任务入队即可
代码:
#include <cstdio> #include <cstring> #include <queue> using namespace std; char str[10]; struct Task { int t, q, p; Task(){} Task(int t, int q, int p) { this->t = t; this->q = q; this->p = p; } bool operator < (const Task& a) const { if (t != a.t) return t > a.t; return q > a.q; } }; priority_queue<Task> Q; int main() { int a, b; while (~scanf("%s", str) && str[0] != '#') { scanf("%d%d", &a, &b); Q.push(Task(b, a, b)); } int k; scanf("%d", &k); while (k--) { Task now = Q.top(); Q.pop(); printf("%d\n", now.q); now.t += now.p; Q.push(now); } return 0; }
UVA 1203 - Argus(优先队列),布布扣,bubuko.com
标签:style http color os io re c 代码
原文地址:http://blog.csdn.net/accelerator_/article/details/38120831