【BZOJ】2456: mode

http://www.lydsy.com/JudgeOnline/problem.php?id=2456

题意:给一个$n<=500000$的数列,求出现次数超过$\lfloor \frac{n}{2} \rfloor$的数

#include <set>
#include <cstdio>

int main() {
	int n, now, tot=1, i, t;
	scanf("%d%d", &n, &now);
	for(i=1; i<n; ++i) { scanf("%d", &t); if(t==now) ++tot; else { if(!tot) now=t, tot=1; else --tot; } }
	printf("%d\n", now);
	return 0;
}

  

= =我滴神啊》。。这题好神...完全没有抓住“出现次数超过n/2”这个条件啊QAQ

如果出现次数超过n/2,那么个数一定大于其余所有数字的个数....于是一一抵消!出现一个抵消一个!

 

posted @ 2015-02-05 15:40  iwtwiioi  阅读(176)  评论(0编辑  收藏  举报