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) ...
随机推荐
- FZU Problem 2028 时空门问题
Problem Description 在一个N*M的地图上旅行.地图上有些地方可以走用. 表示,不能走用 # 表示.在可以走的地方上下左右移动一格需要一个单位时间.可以走的地方还有一些时空之门.时空 ...
- Solr 数字字符不能搜索的一个问题
问题一: 测试人员告诉我数字不能被搜索.于是开始找原因: <fields> ***<field name="productName" type="tex ...
- Mac下Python安装目录
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
- 解析html文档的java库及范例
用这个工具jsoup <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <v ...
- 【转】VMware虚拟机中CentOS设置固定IP
因为需要配置固定IP,在网上找了很久终于找到一个可行的例子,自己配置成功了. 1.首先获取你的GATEWAY 方便后面在cento系统配置里使用选取菜单栏:Edit->Virtual Netwo ...
- php phpmail发送邮件的效果
方法一: /* * 发送邮件 原 smtp ...
- 替换python字典中的key值
- poi 读取数据处理方式
poi读取数据的时候空格,字符数据,数字类型数据处理方式 logger.info("============ExeclReader.readExeclToMapList() begin=== ...
- springmvc集成Freemarke配置的几点
项目结构图 废话不多说, 集成步骤: 1.web.xml spring-mvc配置 <?xml version="1.0" encoding="UTF-8&quo ...
- c++之——多态性
先看一个例子: #include<iostream> using namespace std; class Liberation { public: Liberation(int a):c ...