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. Installation error: INSTALL_FAILED_INSUFFICIENT_STORAGE 解决方法

    最近在做真机测试的时候,经常出现Installation error: INSTAL L_FAILED_INSUFFICIENT_STORAGE这个问题,导致apk没法安装到是手机上,在eclipse ...

  2. DMA2D 图形加速器简介

    在实际使用 LTDC 控制器控制液晶屏时,使 LTDC 正常工作后,往配置好的显存地址写入要显示的像素数据, LTDC 就会把这些数据从显存搬运到液晶面板进行显示,而显示数据的容量非常大,所以我们希望 ...

  3. python下RSA加密解密以及跨平台问题

    Reference:  http://www.cnblogs.com/luchanghong/archive/2012/07/18/2596886.html 项目合作需要,和其他网站通信,消息内容采用 ...

  4. Ajax初窥

    Ajax四个步骤 1. 创建Ajax对象2. 连接到服务器3. 发送请求4. 接收返回值 0x01 创建AJAX对象 方法1(非IE6.0) Var oAjax = new XMLHttpReques ...

  5. drop有default constraint的column

    有时候我们在drop column的时候,会遇到一些default constraints而不能drop,如果我们已经知道constraint name,则可以用下面的语句先把constraint r ...

  6. Extjs 解决在IE 火狐浏览器字体太小问题

    <style type="text/css"> *{font-size:12px!important;} </style>

  7. 路由表及route使用

    路由表 linux下通过route可以查看本地路由表: Kernel IP routing table Destination     Gateway         Genmask         ...

  8. linux下使用yum安装telnet

    参考文章: http://futeng.iteye.com/blog/2039490?utm_source=tuicool&utm_medium=referral

  9. js 区分 safari chrome iso

    网上有很多这个文章的代码,但是在区分safari chrome 没有很好的例子,因为chrome包含了 safari 毕竟他们都是wekit内核,不过利用jquery还是能区分的 在这里分享下吧 -- ...

  10. 怎么让一个div 悬浮在另一个div上

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...