[bzoj2456]mode

来源:互联网 发布:淘宝网怎么删除评论 编辑:程序博客网 时间:2024/06/06 05:35

2456: mode

Time Limit: 1 Sec  Memory Limit: 1 MB
[Submit][Status][Discuss]

Description

给你一个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

Source

很牛(shui)的一道题,1Mb我从来没见过,所以不同数抵消就行了
#include<cstdio>int n,pre,tot;int main(){scanf("%d", &n);for( int i = 1,x; i <= n; i++ ){scanf("%d", &x);if( x == pre ) tot++;else if( !tot ){ pre = x; tot = 1; }else tot--;}printf("%d",pre);return 0;}


原创粉丝点击