UVA 12100 Printer Queue

                  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

用到了关系运算符的重载

关系运算符的定义

关系运算符有==,!=,<,>,<=,>=。

 
 
  1. bool operator == (const A& );
  2. bool operator != (const A& );
  3. bool operator < (const A& );
  4. bool operator <= (const A& );
  5. bool operator > (const A& );
  6. 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值