UVA 12100 Printer Queue
来源:互联网 发布:透视衣服软件 编辑:程序博客网 时间:2024/04/29 05:34
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
用到了关系运算符的重载
关系运算符的定义
关系运算符有==,!=,<,>,<=,>=。
bool operator == (const A& );
bool operator != (const A& );
bool operator < (const A& );
bool operator <= (const A& );
bool operator > (const A& );
bool operator >= (const A& );
还有就是优先队列的使用,因为是结构体所以要用到运算符重载。。
#include<iostream>#include<cstdio>#include<cstring>#include<queue>using namespace std;struct node{ int num,level; bool operator<(const node &a)const//关系运算符<的重载 { return level<a.level; }};int main(){ int t; cin>>t; while(t--) { queue<node>q; priority_queue<node>qq; struct node a; int n,m; cin>>n>>m; int i; for(i=0;i<=n-1;i++) { scanf("%d",&a.level); a.num=i; q.push(a); qq.push(a); } int ans=0; while(1) { if(qq.top().level==q.front().level) { ans++; a=q.front(); qq.pop(); q.pop(); if(a.num==m) break; } else { a=q.front(); q.pop(); q.push(a); } } cout<<ans<<endl; } return 0;}
- UVa 12100 Printer Queue
- UVA - 12100 Printer Queue
- UVa 12100 - Printer Queue
- UVa 12100 - Printer Queue
- UVa: 12100 - Printer Queue
- UVa 12100 - Printer Queue
- uva 12100 Printer Queue
- Uva - 12100 - Printer Queue
- UVA 12100 Printer Queue
- UVa 12100 - Printer Queue
- uva 12100 Printer Queue
- UVA 12100 Printer Queue
- Uva 12100 Printer Queue
- UVA - 12100 Printer Queue 数组
- UVa 12100 - Printer Queue(模拟)
- UVa 12100 - Printer Queue(模拟)
- UVa 12100 Printer Queue(习题5-7)
- Printer Queue 打印队列 UVA 12100
- 解决mysql无法插入中文数据及插入后显示乱码的问题
- 自学PHP与培训PHP的到底有多大的差距?
- springboot整合redis缓存
- 饿了么订单--快到碗里来
- 不敢发了,一不小心就没有了
- UVA 12100 Printer Queue
- 数据库
- 处处吻(粤语汉字英译)
- NOIP2016 day1T2--BZOJ4719 天天爱跑步--LCA+差分
- java编程 android编程的区别
- /***/面试题:求相交链表的交点
- 泛型
- plc c脚本(c script) socket通信
- 论文流程图——使用VISIO制作论文中的流程图[进阶版]