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

用到了关系运算符的重载

关系运算符的定义

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

  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;}


原创粉丝点击