nyoj 95


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

posted on 2017-08-01 10:34  yjbjingcha  阅读(92)  评论(0编辑  收藏  举报

导航