bzoj2456: mode

mac2022-07-05  34

题目链接

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

转载于:https://www.cnblogs.com/sssy/p/9398099.html

相关资源:25个经典网站源代码
最新回复(0)