题意:找出一串数字中出现次数大于等于(n+1)/2的数
思路:DP专题找的题,结果用map计数直接过了,算是水题吧
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;
const int maxn = 1000005;
int n;
int main()
{
while (cin >> n) {
map<int, int> cnt;
int ok = 0;
for (int i = 0; i < n; i++) {
int t;
scanf("%d", &t);
cnt[t]++;
if (cnt[t] >= (n+1)/2 && !ok) {
printf("%d\n", t);
ok = 1;
}
}
}
return 0;
}