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 ...
随机推荐
- Spring IOC的理解
学习过Spring框架的人一定都会听过Spring的IoC(控制反转) .DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC .DI这两个概念是模糊不清的,是很难理 ...
- Linux下产生随机密码10方法
有特殊符号的: cat /dev/urandom | tr -dc "a-zA-Z0-9_+\~\!\@\#\$\%\^\&\*"| fold -w 16 |head -n ...
- InnoDB的Named File Formats
随着InnoDB存储引擎的发展,新的页数据结构有时用来支持新的功能特性.比如前面提到的InnoDB Plugin,提供了新的页数据结构来支持表压缩功能,完全溢出的(Off page)大变长字符类型字段 ...
- elasticsearch查询模板
{ "from":#from#, "size":#size#, "_source":#source#, "query": ...
- KB2533623 下载
服务器上要部署.NET Core 的环境, 先要在服务器上安装Core SDK.直达连接 下载安装一切顺利: 下面开始检验是否正确安装了↓ 运行→cmd→dotnet 结果报错↓ Failed to ...
- html的map自适应
Map常识 请自己看吧:http://www.w3school.com.cn/tags/tag_map.asp Map自适应 <!DOCTYPE html> <html> &l ...
- lzo压缩格式文件查看
使用lzop命令解压并查看 :lzop -cd xxx.lzo |more 附压缩命令:lzop xxx.log (生成xxx.log.lzo) 其它参数: # lzop -v test # 创建te ...
- oracle建表的时候同时创建主键,外键,注释,约束,索引
--主键create table emp (id number constraint id_pr primary key ,name1 varchar(8));create table emp9 (i ...
- css-ie6下实现最小,最大宽度
_width: expression((document.documentElement.clientWidth||document.body.clientWidth)<1040?"1 ...
- magento获取一些值的方法函数
1显示产品列表页(列表.PHTML).echo $this->getProductListHtml(); 2.得到你的Magento的页面的路径. echo $this->getUrl( ...