首页 > 其他 > 详细

UVA 1203 - Argus(优先队列)

时间:2017-04-24 13:45:04      阅读:162      评论:0      收藏:0      [点我收藏+]

UVA 1203 - Argus

题目链接

题意:给定一些注冊命令。表示每隔时间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(优先队列)

原文:http://www.cnblogs.com/lxjshuju/p/6756465.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!