option=com_onlinejudge&Itemid=8&page=show_problem&problem=3644" target="_blank" style="">题目链接:uva 1203 - Argus

题目大意:一个成为Argus的系统。支持一个Register命令

Register Q_num Period

该命令为一个祖冊出发器,每Period产生一次Q_num的时间。要求模拟k个事件,假设多个事件同一时候发生,现处理Q_num小的。

解题思路:用优先队列维护就可以,队列中依照时间小的优先。时间同样的比較Q_num,每次处理完一个时间。相应的将时间的时间加上period后放回队列中,表示下一次出发器生成的时间。

#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm> using namespace std; struct item {
int num, period, ti;
bool operator < (const item& a) const {
return ti > a.ti || (ti == a.ti && num > a.num);
}
}; int main () {
priority_queue<item> pri_que;
char str[105]; while (scanf("%s", str) == 1 && str[0] != '#') {
item u;
scanf("%d%d", &u.num, &u.period);
u.ti = u.period;;
pri_que.push(u);
} int Q;
scanf("%d", &Q);
for (int i = 0; i < Q; i++) {
item u = pri_que.top();
pri_que.pop(); printf("%d\n", u.num);
u.ti += u.period;
pri_que.push(u);
}
return 0;
}

uva 1203 - Argus(优先队列)的更多相关文章

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

    UVA 1203 - Argus 题目链接 题意:给定一些注冊命令.表示每隔时间t,运行一次编号num的指令.注冊命令结束后.给定k.输出前k个运行顺序 思路:用优先队列去搞,任务时间作为优先级.每次 ...

  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. redis关闭保护模式

    1. set key出现的报错 在192.168.56.57客户端登录192.168.56.56的redis服务器时,报错如下: [root@localhost src]# ./redis-cli - ...

  2. PHP 执行系统外部命令的函数- system() exec() passthru()

    PHP 执行系统外部命令的函数: system() exec() passthru()区别:system() 输出并返回最后一行shell结果.exec() 不输出结果,返回最后一行shell结果,所 ...

  3. find tar排除指定文件或目录操作及查找文件内容关键字

    1.find查找排除单个目录 查找当前目录或者子目录下所有.txt文件,但是跳过子目录sk find . -path "./sk" -prune -o -name "*. ...

  4. Hadoop(八)Hadoop数据压缩与企业级优化

    一 Hadoop数据压缩 1.1 概述 压缩技术能够有效减少底层存储系统(HDFS)读写字节数.压缩提高了网络带宽和磁盘空间的效率.在Hadood下,尤其是数据规模很大和工作负载密集的情况下,使用数据 ...

  5. day2、购物商城

    作业:购物商城 商品展示,价格 买,加入购物车 付款,钱不够 代码如下: import codecs #登录接口,用户名密码都正确登录成功,否则失败 def login(your_name,your_ ...

  6. Linux的权限对于文件与目录的意义

    权限对文件: r:可读取此文件的实际内容. w:可以编辑.新增或者是修改该文件的内容(但不含删除该文件),如果没有r权限,无法w. x :该文件具有被系统执行的权限.可以删除. 权限对目录: r:re ...

  7. DotNetOpenAuth实践之WebApi资源服务器

    系列目录: DotNetOpenAuth实践系列(源码在这里) 上篇我们讲到WCF服务作为资源服务器接口提供数据服务,那么这篇我们介绍WebApi作为资源服务器,下面开始: 一.环境搭建 1.新建We ...

  8. mvc bundle的介绍及使用 转载自 http://www.ityouzi.com/archives/mvc-bundleconfig.html

    Asp.Net MVC4 BundleConfig文件合并.压缩,网站优化加速 浏览器在向服务器发送请求的时候,请求的文件链接数量是有限制的,如果页面文件少就没有什么问题了,如果文件太多就会导致链接失 ...

  9. jupyter notebook :一个交互式计算和开发环境

    一. IPython基础 代码自动补全:Tab键 可补全内容包括:变量名.函数名.成员变量函数.目录文件 内省(Itrospection) 在变量名之前或之后加上问号(?),这样可以显示这个对象的相关 ...

  10. latex常用命令

    首行不缩进:在顶格的段落前面加上 \noindent 增加空格:\vspace{长度}:精确增加垂直距离,\hspace{长度} 与 \addvspace{长度}:增加高度长度的垂直空间 在公式的上. ...