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. java版云笔记(四)

    页面的笔记本加载完成了,接下来就是点击笔记本显示将笔记显示,同时把笔记在右边的编辑器中,同时把编辑后的笔记更新. 注:这个项目的sql文件,需求文档,需要的html文件,jar包都可以去下载,下载地址 ...

  2. Learning a Deep Compact Image Representation for Visual Tracking

    这篇博客对论文进行了部分翻译http://blog.csdn.net/vintage_1/article/details/19546953,不过个人觉得博主有些理解有误. 这篇博客简单分析了代码htt ...

  3. hdu 5692(dfs序+线段树,好题)

    Snacks Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  4. Valid Parentheses——栈经典

    Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...

  5. [目标检测]RCNN系列原理

    1 RCNN 1.1 训练过程 (1) 训练时采用fine-tune方式: 先用Imagenet(1000类)训练,再用PASCAL VOC(21)类来fine-tune.使用这种方式训练能够提高8个 ...

  6. centos7 mongodb3.4 安装

    上传tgz 安装包 [root@localhost install_pack]# ll total 274840 -rw-r--r--. 1 root root 9393241 Jun 2 14:36 ...

  7. 字典dict常用方法

    字典是列表中常用的方法,我们经常处理字典,字典嵌套,很多复杂的操作都来自于基础,只是改变了样式而已,本质是不变的.下面来看看字典中常用的功能都有那些:     1.clear(self) def cl ...

  8. svm 中采用自动搜索参数的方式获得参数值

    载时自http://blog.csdn.net/u011177305/article/details/46458801?locationNum=1 OpenCV中SVM类是提供了优化参数值功能的,下面 ...

  9. 【WPF】生成二维码

    第一步,下载Google的ZXing类库,以便引用: BitMatrix bitMatrix; private void Button_Click_1(object sender, RoutedEve ...

  10. (10) go 错误

    没有 try catch..f.. 自定义错误