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 ...
随机推荐
- 在VirtualBox上安装CentOS7
文章的出处:http://jingyan.baidu.com/article/9c69d48f8ec01613c8024e58.html 工具: VirtualBox-5.1.2-108956-Win ...
- mybatis学习笔记三(关联关系)
学习mybatis的关联关系,主要注解在代码上,这里不做解释.配置文件一样的就不贴了 1.关联关系表创建(学生对应老师 多对一) 学生老师表 2.表对应的实体类 package com.home.en ...
- C# 图形普通处理,resize ,水印..
网站中,对用户图片上传处理是很有必要的.对于一些常用的处理,对图片各种形式的压缩,各种形式的水印. 1.裁剪正方形头像方法 /// <summary> /// 正方型裁剪 /// 以图片中 ...
- JTable
final Table table = new Table(parent, SWT.NONE | SWT.FULL_SELECTION); final GridData gd = new GridDa ...
- js数组操作-打乱数组
<style> html, body { margin: 0; padding: 0;} div span { display: inline-block; width: 25px; he ...
- layer ifram 弹出框
父层 <div class="col-xs-4 text-left" style="padding-left: 50px;"><button ...
- 2016NOMS全国运营峰会——史上更强嘉宾阵容提前揭晓!
参加2016NOMS全国运营峰会的演讲嘉宾来自运营领域的各个方面,包括用户运营.内容运营.活动运营.数据运营等.自大会消息一出立刻受到业界的广泛关注,并吸引了众多业内人士踊跃报名.日前,这一运营界峰会 ...
- db2 备份还原
一.导入导出 ixf: db2 export to /tmp/xxx.csv of ixf lobs to . xml to . modified by codepage=1208 "sel ...
- Java NIO Channel之FileChannel [ 转载 ]
Java NIO Channel之FileChannel [ 转载 ] @author zachary.guo 对于文件 I/O,最强大之处在于异步 I/O(asynchronous I/O),它允许 ...
- 【转】如何将ACCESS数据库后缀名accdb改为mdb
office 2007中的ACCESS数据库保存时,默认的后缀名是*.accdb, 但是在数据库编程中,用到的后缀名却是*.mdb, 不能直接将后缀名由 accdb 改为 mdb,虽然没有出错,但是编 ...