UVA 1203 - Argus(优先队列)
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(优先队列)的更多相关文章
- uva 1203 - Argus(优先队列)
option=com_onlinejudge&Itemid=8&page=show_problem&problem=3644" target="_blank ...
- uva 1203 - Argus
简单的优先队列的应用: 代码: #include<queue> #include<cstdio> using namespace std; struct node { int ...
- UVA 11997 STL 优先队列
题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- LA-3135 - Argus(优先队列)
3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples incl ...
- UVa 10954 (Huffman 优先队列) Add All
直接用一个优先队列去模拟Huffman树的建立过程. 每次取优先队列前两个数,然后累加其和,把这个和在放入到优先队列中去. #include <cstdio> #include <q ...
- poj 2051 Argus(优先队列)
题目链接: http://poj.org/problem?id=2051 思路分析: 优先级问题,使用优先队列求解:当执行某个任务后,再增加一个任务到队列中, 该任务的优先级为执行任务的时间加上其时间 ...
- Ugly Numbers UVA - 136(优先队列+vector)
Problem Description Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence 1, ...
- ZOJ2212 Argus 优先队列 结构体
#include <iostream> #include <string> #include <queue> using namespace std; struct ...
- 紫书 例题8-11 UVa 10954 (优先队列)
解法和合并果子是一样的, 每次取最小的两个, 更新答案, 加入队列 #include<cstdio> #include<queue> #define REP(i, a, b) ...
随机推荐
- cvs history,CVS中查询目录下所有文件的提交记录
我们习惯用eclipse svn中查看一个目录下,甚至整个工程下,所有的文件的变更列表:操作为:右键工程 -> Team -> Show History. 最近在使用CVS,eclipse ...
- mac下两种很常见的button的xib设置
第一种,双变button.就是有两种状态的button:普通态和点击选中态. 第二种,点变button.有两种状态:普通态和mouseDown的态,mouseUp时同普通态.
- 用C++画光(三)——色散
写在前面 源码:https://github.com/bajdcc/GameFramework/blob/master/CCGameFramework/base/pe2d/Render2DScene5 ...
- 快速了解Log4J
http://liuzhijun.iteye.com/blog/1746571 ******************** Log4J的三个组件: Logger:日志记录器,负责收集处理日志记录 ...
- Office 2013 Excel 打开文档很慢很慢的解决方法
这个问题查了很多案例,试了很多方法,但是只有下面这个方法有用! 这几天打开excel文档很慢很慢,双击之后好久没反应,过会儿它才慢慢冒出来,当时将就了,刚刚休息的时候想着查一下吧,不然很影响工作效率! ...
- AX88772B 驱动移植
Linux kernel 3.2.0 捏自带的AX88772B 不稳定,现用 AX88772B 官方的驱动进行移植测试. 驱动下载地址: http://www.asix.com.tw/cs/produ ...
- C#里面的三种定时计时器:Timer
在.NET中有三种计时器:1.System.Windows.Forms命名空间下的Timer控件,它直接继承自Componet.Timer控件只有绑定了Tick事件和设置Enabled=True后才会 ...
- 修改jdk
(一)修改jdk的path: (二)修改eclipse里面的jre环境 (三)修改具体项目的jre环境 build path -> config build path (四)修改服务运行环境
- Canvas 实现图片合成并下载合成图片
现在经常会遇到那种带二维码的推广图片,如下图所示: 1是整张推广图的背景,2是二维码.这种图片的背景是保持不变的,里面的二维码是变化的.所以我们需要把二维码单独生成然后与背景合并. 我们可以通过can ...
- json_decode() expects parameter 1 to be string, object given
$data = Weann\Socialite\Facades\Socialite::driver('wechat')->user();//是字符串 $data=json_encode($dat ...