【习题 5-7 UVA - 12100】Printer Queue
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
用队列和multiset就能完成模拟
【代码】
#include <bits/stdc++.h>
using namespace std;
int n, m;
queue <pair<int,int> > dl;
multiset <int,greater<int> > mset;
int main()
{
//freopen("F:\\rush.txt", "r", stdin);
int T;
scanf("%d", &T);
while (T--)
{
mset.clear();
while (!dl.empty()) dl.pop();
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
{
int x;
scanf("%d", &x);
dl.push(make_pair(x,i));
mset.insert(x);
}
int t = 0;
for (int i = 0;i < n;i++)
{
while (dl.front().first != (*mset.begin()) )
{
dl.push(dl.front());
dl.pop();
}
mset.erase(mset.begin());
t++;
if (dl.front().second == m)
{
printf("%d\n", t);
break;
}
dl.pop();
}
}
return 0;
}
【习题 5-7 UVA - 12100】Printer Queue的更多相关文章
- uva 12100 Printer Queue
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- UVa 12100 Printer Queue(queue或者vector模拟队列)
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- UVa 12100 Printer Queue (习题 5-7)
传送门:https://uva.onlinejudge.org/external/121/12100.pdf 题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), ...
- uva 12100 Printer Queue 优先级队列模拟题 数组模拟队列
题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...
- 12100 Printer Queue(优先队列)
12100 Printer Queue12 The only printer in the computer science students’ union is experiencing an ex ...
- 【UVA】12100 Printer Queue(STL队列&优先队列)
题目 题目 分析 练习STL 代码 #include <bits/stdc++.h> using namespace std; int main() { int t; sc ...
- Printer Queue UVA - 12100
The only printer in the computer science students' union is experiencing an extremely heavy workload ...
- Printer Queue
Description The only printer in the computer science students' union is experiencing an extremely he ...
- POJ 3125 Printer Queue
题目: Description The only printer in the computer science students' union is experiencing an extremel ...
- [刷题]算法竞赛入门经典(第2版) 5-7/UVa12100 - Printer Queue
题意:一堆文件但只有一个打印机,按优先级与排队顺序进行打印.也就是在一个可以插队的的队列里,问你何时可以打印到.至于这个插队啊,题目说"Of course, those annoying t ...
随机推荐
- C++的继承和Java继承的比较
在C++中继承可分为公有继承(public)保护继承(protected)和私有继承(private),而在Java中默认只有一种继承(相当于C++中的公有继承)下面我们来看一段代码 #include ...
- Myeclipse学习总结(3)——Myeclipse中的代码格式化、注释模板及保存时自动格式化
设置Myeclipse中的代码格式化.注释模板及保存时自动格式化 1:设置注释的模板: 下载此模板: codetemplates.xml This XML file does not appear ...
- CSUOJ 1554 SG Value
1554: SG Value Time Limit: 5 Sec Memory Limit: 256 MBSubmit: 140 Solved: 35 Description The SG val ...
- RGB 颜色空间转 HSI 颜色空间的matlab程序实现
RGB 颜色空间转 HSI 颜色空间的matlab程序实现 2014.10.20之前的内容有误,这里依据wikipedia更新了算法内容. 算法以wiki为准 https://en.wikipedia ...
- Python和C|C++的混编(二):利用Cython进行混编
还能够使用Cython来实现混编 1 下载Cython.用python setup.py install进行安装 2 一个实例 ① 创建helloworld文件夹 创建helloworld.pyx,内 ...
- Elasticsearch之es学习工作中遇到的坑(陆续更新)
1:es集群脑裂问题(不要用外网ip,节点角色不要混用) 原因1:阿里云服务器,外网有时候不稳定. 解决方案:单独采购服务器,内网安装 原因2:master和node节点没有分开 解决方案: 分角色: ...
- 解决使用SecureCRT不能连接Ubuntu的问题
一.现象 SecureCRT是远程登陆工具及串口,可以远程进行登陆Linux服务器或者串口打印数据.但我下载安装了之后想通过SecureCRT来远程登陆我的Ubuntu,出现一直连接不上. 二.问题原 ...
- [JWT] JWT Signature With RS256 - Learn The Advantages Compared to HS256
The advantage of RS256 over HS256 is RS256 no longer need to share the secret key between client and ...
- HTML基础第十二讲---链接标志
转自:https://i.cnblogs.com/posts?categoryid=1121494 没有链接,WWW将失去存在的意义!WWW之所以受欢迎,乃在于她除了有精美的图文之外,更有方便且多样化 ...
- 常用加密算法的Java实现(一)
常用加密算法的Java实现(一) ——单向加密算法MD5和SHA 摘自:http://www.blogjava.net/amigoxie/archive/2014/06/01/414299.html ...