/*
* 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(优先队列的使用)的更多相关文章

  1. POJ 3125 Printer Queue

    题目: Description The only printer in the computer science students' union is experiencing an extremel ...

  2. POJ 3125 Printer Queue(队列,水题)

    题意:有多组数据,每组数据给出n,m,n表示需要打印的文件个数,m表示要打印的目标位置(m为0~n-1).    接下来给出n个数,第i个值对应第i-1个位置的优先级大小.    打印规则如下:    ...

  3. (队列的应用5.3.2)POJ 2259 Team Queue(队列数组的使用)

    /* * POJ_2259.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...

  4. J - Printer Queue 优先队列与队列

    来源poj3125 The only printer in the computer science students' union is experiencing an extremely heav ...

  5. poj 3053 Fence Repair(优先队列)

    题目链接:http://poj.org/problem?id=3253 思路分析:题目与哈夫曼编码原理相同,使用优先队列与贪心思想:读入数据在优先队列中,弹出两个数计算它们的和,再压入队列中: 代码如 ...

  6. poj 2259 Team Queue

    Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2977   Accepted: 1092 Descri ...

  7. POJ 3481 Double Queue STLmap和set新学到的一点用法

    2013-08-08 POJ 3481  Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是 ...

  8. poj 3253 Fence Repair 优先队列

    poj 3253 Fence Repair 优先队列 Description Farmer John wants to repair a small length of the fence aroun ...

  9. UVa 12100 Printer Queue(queue或者vector模拟队列)

    The only printer in the computer science students' union is experiencing an extremely heavy workload ...

随机推荐

  1. Elasticsearch 删除索引下的所有数据

    下面是head中操作的截图 #清空索引 POST quality_control/my_type/_delete_by_query?refresh&slices=5&pretty { ...

  2. FastReport.Net使用:[4]分组

    1.绘制报表标题和栏首. 2.设置报表栏,为数据区添加一个分组 3.右键分组页眉,在其右键菜单中选择“编辑”,显示分组编辑对话框. 设置分组条件,可直接通过下拉菜单选择Table表中的[学号]列:也能 ...

  3. 【CF contest/792/problem/E】

    E. Colored Balls time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  4. 【manacher+FFT】BZOJ3160-万径人踪灭

    [题目大意] 在一个仅仅含有a,b的字符串里选取一个子序列,使得: 1.位置和字符都关于某条对称轴对称: 2.不能是连续的一段. [思路] 不连续的回文串的个数=总的回文串个数-连续回文串的个数. 后 ...

  5. bzoj 1264: [AHOI2006]基因匹配Match

    1264: [AHOI2006]基因匹配Match Description 基因匹配(match) 卡卡昨天晚上做梦梦见他和可可来到了另外一个星球,这个星球上生物的DNA序列由无数种碱基排列而成(地球 ...

  6. Apache URLRewrite 原理及配置实现

    看一下网站上的一些 URL.您是否发现一些类似于 http://yoursite.com/info/dispEmployeeInfo. ... 99&type=summary的 URL?或者, ...

  7. 01-项目简介Springboot简介入门配置项目准备

    总体课程主要分为4个阶段课程: ------------------------课程介绍------------------------ 01-项目简介Springboot简介入门配置项目准备02-M ...

  8. Educational Codeforces Round 11 D. Number of Parallelograms 暴力

    D. Number of Parallelograms 题目连接: http://www.codeforces.com/contest/660/problem/D Description You ar ...

  9. VK Cup 2016 - Qualification Round 2 A. Home Numbers 水题

    A. Home Numbers 题目连接: http://www.codeforces.com/contest/638/problem/A Description The main street of ...

  10. PAT甲级1057. Stack

    PAT甲级1057. Stack 题意: 堆栈是最基础的数据结构之一,它基于"先进先出"(LIFO)的原理.基本操作包括Push(将元素插入顶部位置)和Pop(删除顶部元素).现在 ...