HDU - 1029 Ignatius and the Princess IV(暴力)
来源:互联网 发布:编程之道 pdf 编辑:程序博客网 时间:2024/05/14 22:05
题目大意:给出奇数个数组,要求你找出出现次数大于等于一半的数字
解题思路:排序,暴力找
#include <cstdio>#include <algorithm>using namespace std;const int N = 1000010;int n;int num[N];void init() { for (int i = 0; i < n; i++) scanf("%d", &num[i]); sort(num, num + n);}void solve() { int Max = (n + 1) / 2; int cnt = 1, tmp = num[0]; for (int i = 1; i < n; i++) { if (num[i] == tmp) { cnt++; } else { if (cnt >= Max) { printf("%d\n", tmp); cnt = -1; break; } cnt = 1; tmp = num[i]; } } if (cnt >= Max) { printf("%d\n", tmp); }}int main() { while (scanf("%d", &n) != EOF) { init(); solve(); } return 0;}
0 0
- HDU - 1029 Ignatius and the Princess IV(暴力)
- 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
- 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
- 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
- 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
- HDU-1029-Ignatius and the Princess IV
- HDU - 1024 Max Sum Plus Plus(DP + 滚动数组)
- imread
- String,StringBuffer,StringBuild的区别
- HTML元素是什么?
- PAT(甲级)1038
- HDU - 1029 Ignatius and the Princess IV(暴力)
- Hadoop源代码学习
- 2015武汉校园招聘归来
- PAT(甲级)1039
- hdu2089(数位dp)
- linux 裁剪 http://blog.csdn.net/jinsen/article/details/4890970
- Android UI之ViewPager
- 达内学习的一些MyBatis笔记
- C#为对话框form添加圆弧拐角