UVA 1203 - Argus(优先队列)

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;
}
时间: 2024-10-11 10:52:29

UVA 1203 - Argus(优先队列)的相关文章

uva 1203 - Argus(优先队列)

题目链接:uva 1203 - Argus 题目大意:一个成为Argus的系统,支持一个Register命令 Register Q_num Period 该命令为一个祖册出发器,每Period产生一次Q_num的时间.要求模拟k个事件,如果多个事件同时发生,现处理Q_num小的. 解题思路:用优先队列维护即可,队列中按照时间小的优先,时间相同的比较Q_num,每次处理完一个时间,对应的将时间的时间加上period后放回队列中,表示下一次出发器生成的时间. #include <cstdio> #

LA-3135 - Argus(优先队列)

3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensordata, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logsand telephone call records. Likewise

LA 3135 Argus (优先队列的简单应用)

A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensordata, Internet traffic, nancial tickers, on-line auctions, and transaction logs such as Web usage logsand telephone call records. Likewise, queries over

poj 2051 Argus(优先队列)

题目链接: http://poj.org/problem?id=2051 思路分析: 优先级问题,使用优先队列求解:当执行某个任务后,再增加一个任务到队列中, 该任务的优先级为执行任务的时间加上其时间间隔,如此反复直到求出前K个执行任务. 代码: #include <iostream> #include <queue> using namespace std; struct Argu { int QNum; int period; int time; bool operator&l

UVA 10954- Add All(优先队列)

Add All Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Problem F Add All Input: standard input Output: standard output Yup!! The problem name reflects your task; just add a set of numbers. But you may

UVA FILL(BFS + 优先队列)

Problem D FILL There are three jugs with a volume of a, b and c liters. (a, b, and c are positive integers not greater than 200). The first and the second jug are initially empty, while the third is completely filled with water. It is allowed to pour

UVa 10954 (Huffman 优先队列) Add All

直接用一个优先队列去模拟Huffman树的建立过程. 每次取优先队列前两个数,然后累加其和,把这个和在放入到优先队列中去. 1 #include <cstdio> 2 #include <queue> 3 using namespace std; 4 5 int main() 6 { 7 int n; 8 while(scanf("%d", &n) == 1 && n) 9 { 10 priority_queue<int, vect

fzu 1182 Argus 优先队列

#include<stdio.h> #include<string.h> #include<queue> #include<algorithm> using namespace std; struct node { int num; int t; int now; friend bool operator < (node n1,node n2) { if(n1.now==n2.now) return n2.num<n1.num; return n

UVA 11573 - Ocean Currents【BFS+优先队列】

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2620 题意:给定一个海面,数字分别代表海流方向,顺着海流不用费能量,逆海流要费1点能量,每次询问给一个起点一个终点,问起点到终点耗费的最小能量 思路:广搜,队列用优先队列,每次取能量最低的点. 代码: #include <stdio.h> #include <