(队列的应用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 ...
随机推荐
- 【BZOJ 4035】 4035: [HAOI2015]数组游戏 (博弈)
4035: [HAOI2015]数组游戏 Time Limit: 15 Sec Memory Limit: 32 MBSubmit: 181 Solved: 89 Description 有一个长 ...
- HDU3585 Information Disturbing 树形dp+二分
http://acm.split.hdu.edu.cn/showproblem.php?pid=3586 题意 : 给定一个带权无向树,要切断所有叶子节点和1号节点(总根)的联系,每次切断边的费用 ...
- django自定义分页控件
1.准备数据 在models创建测试表 from django.db import models class Host(models.Model): hostname = models.CharFie ...
- php上传文件常见问题(基础)
既然上一篇文章<php上传中文文件文件名乱码问题>遇到了文件上传的问题,干脆把php上传文件时经常碰到的几个问题总结一下吧,以后用到时不用再去找了. 1.先做个最简单的上传文件 <h ...
- leetcode76. Minimum Window Substring
leetcode76. Minimum Window Substring 题意: 给定字符串S和字符串T,找到S中的最小窗口,其中将包含复杂度O(n)中T中的所有字符. 例如, S ="AD ...
- Linear regulator=low-cost dc/dc converter
The circuit in Figure 1 is a good choice if you need a power supply with high efficiency and you don ...
- Java-方法的覆写
class parent { void print() { System.out.println("parent"); } } class child extends p ...
- tomcat JVM内存 配置
原文:http://elf8848.iteye.com/blog/467460 常见的内存溢出有以下两种: java.lang.OutOfMemoryError: PermGen space java ...
- UIView独占响应事件
exclusiveTouch A Boolean value that indicates whether the receiver handles touch events exclusively. ...
- 更为详细的介绍Hadoop combiners-More about Hadoop combiners
Hadoop combiners are a very powerful tool to speed up our computations. We already saw what a combin ...