HDU 1029 - Ignatius and the Princess IV
2017-09-06 15:22
441 查看
题目大意:输入一个奇数N,接着输入N个数,找出其中出现个数为(N+1)/2的数。
解题思路:因为出现次数为奇数+1的一半,也就是出现次数大于N/2的数。用map存下出现的数以及出现的次数。
ac代码:
解题思路:因为出现次数为奇数+1的一半,也就是出现次数大于N/2的数。用map存下出现的数以及出现的次数。
ac代码:
#include <iostream> #include <map> using namespace std; map <int, int>ma; int n, t, re; int main() { while (scanf("%d", &n) != EOF){ for (int i=0; i<n; i++){ scanf("%d", &t); ma[t]++; if (ma[t] > n/2) re = t; } printf("%d\n", re); ma.clear(); } return 0; }
相关文章推荐
- HDU 1029 Ignatius and the Princess IV
- HDU - 1029 Ignatius and the Princess IV(DP)
- hdu 1029 Ignatius and the Princess IV(水题)
- HDU - 1029 B - Ignatius and the Princess IV
- Ignatius and the Princess IV HDU - 1029
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV --- 水题
- HDU 1029 Ignatius and the Princess IV
- 【map/桶记录/基础dp】Ignatius and the Princess IV HDU - 1029
- HDU1029 Ignatius and the Princess IV【排序】
- hdu 1029 Ignatius and the Princess IV(水题)
- HDU_1029 Ignatius and the Princess IV
- Ignatius and the Princess IV hdu 1029
- hdu 1029 Ignatius and the Princess IV
- [思维题] Ignatius and the Princess IV HDU - 1029
- 【HDU】 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV【stl】
- hdu 1029 Ignatius and the Princess IV
- 【HDU】1029 - Ignatius and the Princess IV(STL || 思维)