您的位置:首页 > 其它

nyoj 95

2015-07-30 10:17 113 查看

#include<stdio.h>

#include<queue>

#include<algorithm>

using namespace std;

struct node

{

bool operator()(int &x,int &y)//优先级

{

return x>y;

}

};

priority_queue<int,vector<int>,node> que;//队列

int main()

{

int n;

scanf("%d",&n);

while(n--)

{

int m,x;

scanf("%d",&m);

for(int i=0;i<m;i++)//输入数值

{

scanf("%d",&x);

que.push(x);

}

int max=0,k=1,l,a;

a=que.top();

que.pop();

while(!que.empty())

{

if(que.top()==a)//如果相等

{

que.pop();

k++;//加一

if(max<k)//更新max

{

max=k;

l=a;//记录top

}

}

else//不相等,更新a的值

{

a=que.top();

que.pop();

k=1;

}

}

printf("%d %d\n",l,max);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: