bzoj2456: mode

题目链接

bzoj2456: mode

题解

不同的随机消去,超过一半的最后一定有余

代码

#include<cstdio> 
inline int read() { 
    int x = 0; 
    char c = getchar(); 
    while(c  < '0' || c > '9')  c = getchar();
    while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
    return x ; 
} 
int main() { 
    int n = read(),now;
    for(int t,cnt = 0;n --;) {
        t = read(); 
        if(t == now) ++ cnt; 
        else if(!cnt) now = t,++ cnt; 
        else cnt --; 
    } 
    printf("%d
",now); 
    return 0; 
} 

原文地址:https://www.cnblogs.com/sssy/p/9398099.html