bzoj2456 mode

思路:

两两pk,绝对众数最终能够胜出。

实现:

 1 #include <cstdio>
 2 using namespace std;
 3 
 4 int main()
 5 {
 6     int n = 0, cnt = 0, a = 0, now = 0;
 7     scanf("%d", &n);
 8     for (int i = 0; i < n; i++)
 9     {
10         scanf("%d", &a);
11         if (now == a) cnt++;
12         else
13         {
14             cnt--;
15             if (cnt <= 0) { cnt = 1; now = a; }
16         }
17     }
18     printf("%d
", now);
19     return 0;
20 }
原文地址:https://www.cnblogs.com/wangyiming/p/7766496.html