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\n",now);
return 0;
}