bzoj2456

给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数。

Input

第1行一个正整数n。
第2行n个正整数用空格隔开。

Output

    一行一个正整数表示那个众数。

Sample Input

5
3 2 3 1 3

Sample Output

3

HINT

 

100%的数据,n<=500000,数列中每个数<=maxlongint。


 


zju2132 The Most Frequent Number

map瞎搞竟然0msTLE,后来发现都不需要把数字存下来
#include<cstdio>
using namespace std;
int main(){
    int n,i,x;
    scanf("%d",&n);
    int cnt=0,ans;
    for (int i=0;i<n;i++){
    scanf("%d",&x);
        if (cnt==0) ans=x;
        (ans==x) ? cnt++ : cnt--;
    }
    printf("%d",ans);
    return 0;
}    

 

posted @ 2017-09-23 21:25  dancer16  阅读(107)  评论(0编辑  收藏  举报
描述