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. 用C++画光(二)——矩形

    在上篇文章的基础上,做了许多调整,修复了许多BUG.在解决bug的过程中,我逐渐领悟到一个要领:枯燥地一步步调试太痛苦了,找不到问题的根源!所以我选择将中间结果打到图片上.如: (注意,里面的点是我随 ...

  2. 你会用AngularJS,但你会写AngularJS文档么?

    你会用AngularJS,但你会写AngularJS文档么? 涉及知识:gulp javascript 我们经常在写代码的时候要求写好注释,方便日后维护.但其实注释还有一个重要的用途:生成API文档. ...

  3. navicat如何导入sql文件和导出sql文件

    http://jingyan.baidu.com/article/a65957f4976aad24e67f9b9b.html ************************************* ...

  4. 一款纯css3实现的数字统计游戏

    今天给大家分享一款纯css3实现的数字统计游戏.这款游戏的规则的是将所有的数字相加等于72.这款游戏的数字按钮做得很美观,需要的时候可以借用下.一起看下效果图: 在线预览   源码下载 实现的代码. ...

  5. Sqli-LABS通关笔录-5[SQL布尔型盲注]

    /* 请为原作者打个标记.出自:珍惜少年时 */   通过该关卡的学习我掌握到了 1.如何灵活的运用mysql里的MID.ASCII.length.等函数 2.布尔型盲注的认识 3.哦,对了还有.程序 ...

  6. js数组添加或删除元素

    var arr = new Array(); arr[] = "aaa"; arr[] = "bbb"; arr[] = "ccc"; ar ...

  7. 【C#/WPF】ListView的MVVM例子,及禁止拖动ListView的头部Header

    一个ListView的MVVM简单例子: <ListView ItemsSource="{Binding GoodsList}" Margin="0,10,0,10 ...

  8. iOS边练边学--transform的简单介绍并且用transform实现键盘处理

    一.transform:形变属性,能完成功能:平移,缩放,旋转 <平移> // 根据给的移动距离平移 self.tempView.transform = CGAffineTransform ...

  9. style="display:none"隐藏html的标签

    隐藏html的标签 <div class="span11 alignment"> <h1>我的虚拟网络</h1> </div> &l ...

  10. SBT树

    转自:http://jcf94.com/2015/06/19/2015-06-19-sbt/ 总结: 二叉查找树(或称二叉搜索树.二叉排序树):大的右边.小的左边.问题:不平衡,输入有序情况下从平均性 ...