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(优先队列)的更多相关文章

  1. uva 1203 - Argus(优先队列)

    option=com_onlinejudge&Itemid=8&page=show_problem&problem=3644" target="_blank ...

  2. uva 1203 - Argus

    简单的优先队列的应用: 代码: #include<queue> #include<cstdio> using namespace std; struct node { int ...

  3. UVA 11997 STL 优先队列

    题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  4. LA-3135 - Argus(优先队列)

    3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples incl ...

  5. UVa 10954 (Huffman 优先队列) Add All

    直接用一个优先队列去模拟Huffman树的建立过程. 每次取优先队列前两个数,然后累加其和,把这个和在放入到优先队列中去. #include <cstdio> #include <q ...

  6. poj 2051 Argus(优先队列)

    题目链接: http://poj.org/problem?id=2051 思路分析: 优先级问题,使用优先队列求解:当执行某个任务后,再增加一个任务到队列中, 该任务的优先级为执行任务的时间加上其时间 ...

  7. Ugly Numbers UVA - 136(优先队列+vector)

    Problem Description Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, ...

  8. ZOJ2212 Argus 优先队列 结构体

    #include <iostream> #include <string> #include <queue> using namespace std; struct ...

  9. 紫书 例题8-11 UVa 10954 (优先队列)

    解法和合并果子是一样的, 每次取最小的两个, 更新答案, 加入队列 #include<cstdio> #include<queue> #define REP(i, a, b) ...

随机推荐

  1. gulp自动化ES6转ES5

    npm install --save-dev gulp npm install --save-dev gulp-babel npm install --save-dev babel-preset-es ...

  2. C++面向对象程序设计的一些知识点(2)

    1.C++中三种继承方式及派生类中访问控制规则 (1).C++支持的三种继承方式是public.protected.private.C++允许一个类同时以不同的方式对不同的基类加以继承. (2). 不 ...

  3. 1.2.1 工作流管理系统参考模型 (zhuan)

    http://book.51cto.com/art/201009/228705.htm ************************************************* <jB ...

  4. 5种漂亮的纯CSS3动画按钮特效

    这次我们要来分享一款很不错的CSS3按钮动画,这款CSS3按钮一共有5种动画方式,每一种都是鼠标滑过动画形式,虽然这些动画按钮不是十分华丽,但是小编觉得不像其他按钮那样很难扩展,我们可以修改CSS代码 ...

  5. sqlserver被锁的表以及如何解锁

    查看sqlserver被锁的表以及如何解锁   查看被锁表: select   request_session_id   spid,OBJECT_NAME(resource_associated_en ...

  6. Red Hat快捷键操作

    Red Hat快捷键操作 .使用虚拟控制台 登录后按“Alt+F2”键可以看到“login:”提示符, 这就是第二个虚拟控制台. 一般新安装的Linux有四个虚拟控制台, 可以用“Alt+F1”到“A ...

  7. java资料——数据结构(转)

    数据结构 (计算机存储.组织数据方式)                                                                            数据结构是 ...

  8. 也许,这样理解HTTPS更容易(今天看到的, 对https总结最好的一篇)

    摘要:本文尝试一步步还原HTTPS的设计过程,以理解为什么HTTPS最终会是这副模样.但是这并不代表HTTPS的真实设计过程.在阅读本文时,你可以尝试放下已有的对HTTPS的理解,这样更利于" ...

  9. 二、Linux 静态IP,动态IP配置

    Linux 静态IP,动态IP配置 第一步:激活网卡 系统装好后默认的网卡是eth0,用下面的命令将这块网卡激活. # ifconfig eth0 up 第二步:设置网卡进入系统时启动 想要每次开机就 ...

  10. [Eclipse] 项目编码

    一.修改eclipse的新建项目的编码 在菜单栏的 Window->Preferences->General->Workspace->Text file encoding 将其 ...