UVa12100 Printer Queue (打印队列)
来源:互联网 发布:idg 知乎 编辑:程序博客网 时间:2024/05/01 05:15
12100 Printer Queue
Input
One line with a positive integer : the number of test cases(at most 100). Then for each test case:
• One line with two integers n and m, where n is the number of jobs in the queue (1≤n≤100)
And m is the position of your job (0≤m≤n−1). The first position in the queue is number 0,
the second is number 1,and soon.
• One line with n integers in the range 1 to 9, giving the priorities of the jobs in the queue. The
first integer gives the priority of the first job, the second integer the priority of the second job,
and soon.
Output
For each test case,print one line with a single integer;the number of minutes until your job is completely
printed,as suming that no additional print jobs will arrive.
Sample Input
3
1 0
5
4 2
1 2 3 4
6 0
1 1 9 1 1 1
Sample Output
1
2
5
My Solution
#include <iostream>#include <deque>using namespace std;bool compar(const deque<int> &de){ int cot=0; for(int i=1;i<de.size();i++) //最后一次比较是比较到最后一个的前一个和最后一个/*! ^^^^^^^^^^^ 轮到的这个和后面所有的分别比较*/ { if(de[0]>=de[i]) cot++; //从第二个开始跟它比 } if(cot==de.size()-1) return true; //这里完美的把单个元素的集合包含进去了 else return false;}int main(){ deque<int> priqu; int T=0,n,place,tem,time; cin>>T; while(T--){ cin>>n>>place; priqu.clear(); for(int i=0;i<n;i++){ cin>>tem; priqu.emplace_back(tem); } time=0; int gol=place; while(gol>-1){ //对于本来就在首位i的就不对了,故不是gol>0而是>-1 int i=priqu[0]; //priqu.pop_front();必须放里面 gol--; //******因为下面这里要用到 int siz0=priqu.size(); if(compar(priqu)) { time++; //打印才要时间哦 priqu.pop_front(); continue; } else { priqu.pop_front(); priqu.emplace_back(i); if(gol==-1) gol+=siz0; //!应当是==-1的时候才加,所以加个size()就好了,刚好等于size()-1 } } cout<<time<<endl; } return 0;}
谢谢
- UVa12100 Printer Queue (打印队列)
- UVA12100:Printer Queue(打印队列)
- 习题5-7 打印队列(Printer Queue, UVa12100)
- UVA12100 Printer Queue 【双端队列】
- 算法竞赛入门经典 第二版 习题5-7 打印队列 Printer Queue uva12100
- Printer Queue打印队列
- 打印队列(Printer Queue)
- UVa12100 - Printer Queue
- UVA12100 - Printer Queue
- UVa12100 Printer Queue
- UVA12100 Printer Queue
- uva12100 Printer Queue (队列模拟, 据说是优先队列,错了)
- UVALive3638 UVA12100 POJ3125 HDU1972 Printer Queue【队列+模拟】
- Printer Queue(打印队列)POJ3125
- Printer Queue 打印队列 UVA 12100
- uva 12100 Printer Queue(打印队列)模拟
- UVA12100-打印队列
- queue队列-printer queue
- Maven自定义上传第三方包到3rd party(第三方无依赖jar和本地扩展类加入maven统一管理)
- mac修改hosts访问google
- UVA - 12166 Equilibrium Mobile
- LeetCode -- Jump Game
- LeetCode -- Palindrome Partitioning
- UVa12100 Printer Queue (打印队列)
- LeetCode -- Pow(x, n)
- LeetCode -- Rectangle Area
- 疯狂Html+CSS+JS 中JS总结
- R语言 分层抽样---分层随机抽样(SRS) strata的使用(一)
- Shiro系列之Shiro+Mysql实现用户认证(Authentication)
- 在retina屏中实现1px border效果
- PhantomJS基础及示例
- jquery 选择器写法