打印队列 (Printer Queue,ACM/ICPC NWERC 2006,UVA12100)
题目描述:
题目思路:
使用一个队列记录数字,一个优先队列记录优先级,如果相等即可打印;
#include <iostream>
#include <queue>
using namespace std;
int main(int argc, char *argv[])
{
int t;
cin >> t;
while(t--)
{
int n,pos;
queue<int> q ;
priority_queue<int> pq ;
cin >> n >> pos ;
for(int i=;i<n;i++)
{
int a;
cin >> a;
q.push(a);
pq.push(a);
}
int t = ;
while(true)
{
if(q.front() == pq.top())
{
if(t==pos){cout<<n-q.size()+<<endl;break;}
else{
q.pop();
pq.pop();
t++;
}
}
else{
int temp = q.front();
q.pop();
q.push(temp);
if(t == pos){t=;pos=q.size()-;}
else t++ ; }
}
}
return ;
}
打印队列 (Printer Queue,ACM/ICPC NWERC 2006,UVA12100)的更多相关文章
- 集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)
集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096) 题目描述 有一个专门为了集合运算而设计的"集合栈"计算机.该 ...
- 集合栈计算机 (The SetStack Computer,ACM/ICPC NWERC 2006,UVa12096
题目描述: #include<iostream> #include<string> #include<set> #include<map> #inclu ...
- ACM程序设计选修课——1044: (ds:队列)打印队列(queue模拟)
问题 A: (ds:队列)打印队列 时间限制: 1 Sec 内存限制: 128 MB 提交: 25 解决: 4 [提交][状态][讨论版] 题目描述 网络工程实验室只有一台打印机,它承担了非常繁重 ...
- DNA序列 (DNA Consensus String,ACM/ICPC Seoul 2006,UVa1368
题目描述:算法竞赛入门经典习题3-7 题目思路:每列出现最多的距离即最短 #include <stdio.h> #include <string.h> int main(int ...
- 换抵挡装置 (Kickdown,ACM/ICPC NEERC 2006,UVa1588
题目描述:算法竞赛入门经典习题3-11 题目思路:1.两长条移动匹配 2.上下调换,取小者 #include <stdio.h> #include <string.h> int ...
- UVa 12100 Printer Queue(queue或者vector模拟队列)
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- J - Printer Queue 优先队列与队列
来源poj3125 The only printer in the computer science students' union is experiencing an extremely heav ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- Printer Queue
Description The only printer in the computer science students' union is experiencing an extremely he ...
随机推荐
- PCB测试点的设计要求
测试点的设计要求:1.定位孔采用非金属化的定位孔 ,误差小于0.05mm.定位孔周围3mm不能有元件.2.测试点直径不小于0.8mm,测试点之间的间距不小于1.27mm,测试点离元件不小于1.27mm ...
- 过滤xss攻击脚本
<?php /** * @blog http://www.phpddt.com * @param $string * @param $low 安全别级低 */ function clean_xs ...
- iOS:PrefixHeader / 头文件 / 宏定义(18-03-02更)
宏定义,不一定放在PCH文件,可能放在一个.h文件,再用PCH包含进来. 1.屏幕尺寸 // 屏幕尺寸 #define kSCREEN_WIDTH [UIScreen mainScreen].boun ...
- C++继承细节 -2
继承与动态内存分配 //基类定义 class BaseClass { private: char *label; public: BaseClass() {} BaseClass(const char ...
- try...catch..finally..语句中,finally是否必须存在?作用是什么
try { } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ } 1: ...
- binlog2sql 用法
binlog2sql 用法 使用场景:binlog2sql是根据mysql的binlog (要求格式是row)反解析出delete,update操作,对误操作数据进行还原. https://githu ...
- dubbo配置注意
API接口的路径在provider和consumer端的路径要一致
- tctip打赏小插件
tctip是一个js插件,作用是在web网页右侧生成一个打赏浮动窗 使用方法 页面使用(多数人的使用方式) 插件下载地址 第一步,引入js 一般引入min版本,即引入tctip-版本号.min.js文 ...
- iOS 11.2 - 11.3.1 越狱教程
iOS 11.2 - 11.3.1 越狱教程 一.准备相应的工具 (1) 下载 CydiaImpactor,官网地址是 http://cydiaImpactor.com (2) 下载 Electra, ...
- 10分钟搞定webpack打包
入门前端这个职位近三年的时间了,但是脑子里的东西不多也不少,今天就从脑袋里把新版本的webpack打包过程拔出来给大家鲁一遍,就算帮助那些小白了,废话不多说,开始鲁起来,大家跟着我一起撸... 首先, ...