UVa 12100 Printer Queue (习题 5-7)
传送门:https://uva.onlinejudge.org/external/121/12100.pdf
题意:队列中待打印的任务(1 <= n <= 100)带有优先级(1-9), 打印步骤为每次从队首拿出一个, 如果队列中没有优先级比该任务高的, 打印这个任务; 若有优先级高的, 把这个任务放到队尾, 并打印优先级最高的. 每打印一次耗时1分钟, 求给定任务什么时候打印.
水题A半天 不愧是弱渣..........
最坏的情况需要maxn*maxn的空间........
front rear 记录前后位置
#include <bits/stdc++.h>
using namespace std; const int MAXN = ;
int t, n, m, _time;
int que[MAXN*MAXN]; void process(){
int front = , rear = n;
while(true){
int maxi = que[front];
for(int i = front; i < rear; ++i){
if(que[i] > maxi){
if(front == m) m = rear;
que[rear++] = que[front++];
break;
}
else if(i == rear - ){
++_time;
if(front == m) return ;
front++;
}
}
}
}
int main(){
cin >> t;
while(t--){
_time = ;
cin >> n >> m;
for(int i = ; i < n; ++i) cin >> que[i];
process();
cout << _time << endl;
}
return ;
}
UVa 12100 Printer Queue (习题 5-7)的更多相关文章
- 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 优先级队列模拟题 数组模拟队列
题目很简单,给一个队列以及文件的位置,然后一个一个检查,如果第一个是优先级最高的就打印,否则放到队列后面,求所要打印的文件打印需要花费多长时间. 这里我用数组模拟队列实现,考虑到最糟糕的情况,必须把数 ...
- 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 ...
随机推荐
- 【APEX初步】【2】【sObjects与数据库】
由于apex是与数据库集成的.我们可以直接用apex访问数据库.每条记录就是一个SObject对象
- 获取select选中的值
$("#CalibrationYear option:selected").text();
- Object转换为字符并去空格
<div id="txt" style="display:none">1."不积跬步,无以至千里"的古语说明( A ) A.没有 ...
- String.split()分割字符串
string.split(s[, sep[, maxsplit]]) Return a list of the words of the string s. If the optional secon ...
- PRML 第二章mindmap
PRML第二章的Mindmap,这一章读的比较快,主要是很多计算和证明的过程都跳过了,感觉不是特别需要认真去看每一个公式,能够记住每个小节的结论.公式就可以了.当然有能力.有时间的人还是可以认真读的, ...
- digitalocean Vultr Linode 三家海外vps最新真实情况
中国有大批用户,在使用海外vps服务器.好处是不言而喻的:性价比高.带宽大.免备案.可搭梯子,没有后门监控. 有趣的是,每一年的周期观察,都能发现海外vps对中国大陆的线路速度.可用性变化.过去速度快 ...
- 3.使用secureCRT连接PC,LINUX,开发板
1.设置secureCRT(可选项):http://www.linuxyw.com/linux/gongxiang/20130505/161.html 2.使用secureCRT远程登录linux 3 ...
- JsSIP.UA.JsSIP 总是返回错误:422 Session Interval Too Small
在JsSIP 中 JsSIP.UA.call 总是 返回错误:422 Session Interval Too Small 关于错详情在这篇文章中解释的比较详尽:http://www.cnblogs. ...
- linux命令之crontab详解
crontab命令: crontab -l : 显示定时任务列表 crontab -e: 编辑定时任务 crontab -r : 删除所有定时任务 基本格式 : * * * * * command ...
- 将LibreOffice文档批量转成PDF格式
使用如下命令可以将文档一次性批量导出为pdf格式: -name -I /program/soffice.exe --headless --convert-to pdf '{}' find命令的-max ...