(队列的应用5.3.3)POJ 3125 Printer Queue(优先队列的使用)
/*
* POJ_3125.cpp
*
* Created on: 2013年10月31日
* Author: Administrator
*/ #include <iostream>
#include <cstdio>
#include <queue> using namespace std; int main() {
int t;
scanf("%d", &t);
while (t--) {
queue<int> q;
priority_queue<int> v; int n, m;
scanf("%d%d", &n, &m); int i;
for (i = 0; i < n; ++i) {
int a;
scanf("%d", &a); q.push(a);
v.push(a);
} while (true) {
int x = q.front();
q.pop(); if (m == 0) {//如果m==0,则证明现在打印的是目标任务
if (x != v.top()) {//如果队列中还有优先级比x高的..
m = v.size() - 1;//下标是从0开始的
q.push(x);//将该任务放到队尾
} else {
break;
}
} else {//如果现在的任务还不是目标任务
--m;
if (x != v.top()) {
q.push(x);
} else {
v.pop();
}
} } printf("%d\n", n - q.size());
} return 0;
}
(队列的应用5.3.3)POJ 3125 Printer Queue(优先队列的使用)的更多相关文章
- POJ 3125 Printer Queue
题目: Description The only printer in the computer science students' union is experiencing an extremel ...
- POJ 3125 Printer Queue(队列,水题)
题意:有多组数据,每组数据给出n,m,n表示需要打印的文件个数,m表示要打印的目标位置(m为0~n-1). 接下来给出n个数,第i个值对应第i-1个位置的优先级大小. 打印规则如下: ...
- (队列的应用5.3.2)POJ 2259 Team Queue(队列数组的使用)
/* * POJ_2259.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...
- J - Printer Queue 优先队列与队列
来源poj3125 The only printer in the computer science students' union is experiencing an extremely heav ...
- poj 3053 Fence Repair(优先队列)
题目链接:http://poj.org/problem?id=3253 思路分析:题目与哈夫曼编码原理相同,使用优先队列与贪心思想:读入数据在优先队列中,弹出两个数计算它们的和,再压入队列中: 代码如 ...
- poj 2259 Team Queue
Team Queue Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2977 Accepted: 1092 Descri ...
- POJ 3481 Double Queue STLmap和set新学到的一点用法
2013-08-08 POJ 3481 Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是 ...
- poj 3253 Fence Repair 优先队列
poj 3253 Fence Repair 优先队列 Description Farmer John wants to repair a small length of the fence aroun ...
- UVa 12100 Printer Queue(queue或者vector模拟队列)
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
随机推荐
- python3 django 安装
参考https://www.cnblogs.com/yuyang26/p/7411269.html 前提条件:python3.x环境 windows 步骤1 pip install Django==2 ...
- hibernate4日志配置
在平时运行程序时控制台有很对的日志打印,本文说明如何控制这些日志打印. 1.确定要使用日志的实现,我在这使用的是log4j. 2.加入log4j的api包slf4j-api.jar,log4j的转换包 ...
- [bzoj1023][SHOI2008]cactus 仙人掌图 (动态规划)
Description 如果某个无向连通图的任意一条边至多只出现在一条简单回路(simple cycle)里,我们就称这张图为仙人图(cactus).所谓简单回路就是指在图上不重复经过任何一个顶点的回 ...
- Uva1553 Caves and Tunnels LCT
简单题,主要为了练手. #include <cstdio> #include <iostream> #define maxn 100010 using namespace st ...
- ngxin error日志
日志模块ngx_errlog_module对于支持可变参数平台提供的三个接口 #define ngx_log_error(level, log, ...) \ if ((log)->log_le ...
- hdu 4111 Alice and Bob 记忆化搜索 博弈论
Alice and Bob Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- artDialog双击会关闭对话框的修改
artDialog,一个jquery的对话框插件,很好用的说 但是在使用时发现鼠标双击时会自半对话框,查看源码发现有个监听鼠标双击的事件如下图: 简单的方法就是把该行去掉,为了扩展可改成如下图: 这样 ...
- 移动端 关于 键盘将input 框 顶上去的解决思路---个人见解
在移动端,经常会遇到input获得焦点时候弹出的虚拟键盘将整体页面布局打乱的情况. 比如说是这种 输入框未获得焦点键盘未抬起的时候: 输入框获得焦点键盘抬起的时候 这种情况下,不管是上面的textar ...
- Gulp插件less的使用
1.创建:gulpfile.js var gulp = require('gulp'), less = require('gulp-less'); gulp.task('default', funct ...
- Java Simon--性能瓶颈分析工具
有了AOP以及Javainstrument之后,Java有很多很好的性能监控工具可以很有效的帮助我们分析系统瓶颈.例如使用jvisualvm的gui连接JVM应用之后可以监控应用的各种状态,可以看到每 ...