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) ...
随机推荐
- CCLayer设置anchorPoint无效的问题
最近刚发现一个问题,anchorPoint这个属性虽然是属于CCNode的,但是CCLayer设置anchorPoint没有效果.CCLayer的anchorPoint被默认设定在(0, 0)位置 ...
- mysql 5.7.13 安装配置方法图文教程(win10) (转)
http://www.jb51.net/article/87152.htm ***************************** MySQL是一款关系型数据库管理系统,是由Oracle旗下公司M ...
- form的method用get导致中文乱码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- 使用supervisor过程中的一个问题
我有一个php写的脚本需要常驻内存,于是使用supervisor进行管理,后来由于进程运行时间长了以后会出现假死的情况,所以就改成进程在无事可做的时候就退出,然后让supervisor再拉起来,起到重 ...
- Navicat Premium 链接 ORACLE
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html 下载地址 Navicat Pr ...
- Makefile 7——自动生成依赖关系 三颗星
后面会介绍gcc获得源文件依赖的方法,gcc这个功能就是为make而存在的.我们采用gcc的-MM选项结合sed命令.使用sed进行替换的目的是为了在目标名前加上“objs/”前缀.gcc的-E选项, ...
- binutils工具集之---ar
1.如果要将多个.o文件生成一个库文件,则存在两种类型的库,一种是静态库,在linux里面后缀是.a,另一种是动态库,后缀为.so. 当可执行程序要与静态库进行链接时,所用到的库中的函数和数据会被拷贝 ...
- dp之区间:最大k乘积
题目:给你一个n(1<=n<=15)位数,求将它分成m段,用m-1个*连接起来的最大乘积....... 思路:定义dp[i][j]为将前i位数分成j段的最大乘积,那么dp[i][j]==m ...
- 全屏API接口
HTML5的诞生给我们提供了很多精彩的JavaScript和HTML新功能和新特征.有些新特征我们已知多年并大量的使用,而另外一些主要是用在前沿的手机移动技术上,或者桌面应用中起辅助作用.不管这些HT ...
- iOS 更换键盘的return键的形式
iOS 右下角的return键有很多形式,比如发送,完成换行等,在遵循代理之后调用 -(BOOL)textFieldShouldReturn:(UITextField *)textField{ ret ...