HDU1029 Ignatius and the Princess IV
问题链接:HDU1029 Ignatius and the Princess IV。基础练习题,用C++语言编写。
题意简述:输入n(n是奇数),然后输入n个整数,求出现(n+1)/2次的整数。
问题分析:n是奇数,(n+1)/2是n的一半以上,只要将n个数据排序,出现(n+1)/2次的整数必然会出现在中间位置。
本问题使用C++语言编写的原因是函数sort()的参数简单,使用方便。
AC的C++语言程序如下:
/* HDU1029 Ignatius and the Princess IV */#include <iostream>
#include <algorithm>using namespace std;const int MAXN = 999999;
int data[MAXN];int main()
{int n;while(cin >> n) {for(int i=0; i<n; i++)cin >> data[i];sort(data, data + n);printf("%d\n", data[(n + 1) / 2]);}return 0;
}
转载于:https://www.cnblogs.com/tigerisland/p/7564443.html
HDU1029 Ignatius and the Princess IV相关推荐
- hdu-1029 Ignatius and the Princess IV
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1029 题目类型: 给一个奇数个列的数组,其中一定存在某个数字,该数字的个数是大于一半的,问这个数字是 ...
- HDU1029 - Ignatius and the Princess IV【水题】
给你n个数字,请你找出出现至少(n+1)/2次的数字. 输入 本题包含多组数据,请处理到EOF: 每组数据包含两行. 第一行一个数字N(1<=N<=999999) ,保证N为奇数. 第二行 ...
- HDU1029——Ignatius and the Princess IV
题意:求N个数中出现次数大于等于(N+1)/2的数.因为N是奇数,所以也就是求出现次数一半以上的数. 定义变量ans=第一个数.time=1,向后循环如果和ans相等time++,否则time--,当 ...
- E - Ignatius and the Princess IV
####E - Ignatius and the Princess IV "OK, you are not too bad, em- But you can never pass the n ...
- Hdu 1029 Ignatius and the Princess IV
思路:普通的cin会超时 方法很妙 1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 ...
- HDU - 1029 Ignatius and the Princess IV
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=1029 题目大意 给你n(n为奇数, n < 1e6)个数,让你找到个数 >=( ...
- hdu1027 Ignatius and the Princess II (全排列 amp; STL中的神器)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1027 Ignatiu ...
- LETTers比赛第三场 --1002 Ignatius and the Princess III解题报告
提交人:侯建鹏 提交日期:2012/4/16 1002 Ignatius and the Princess III 解题思路(一):动态规划 先设置int p[N][N]; Dp 方程为:p[i][j ...
- HDU-1026 Ignatius and the Princess I (BFS)
题目:HDU-1026 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 题目: Ignatius and the Princess I Time ...
- 【HDU - 1026 】Ignatius and the Princess I (bfs + 记录路径)
题干: The Princess has been abducted by the BEelzebub feng5166, our hero Ignatius has to rescue our pr ...
最新文章
- boost::sort模块实现相关的浮点排序测试
- nextcloud php 版本,Nextcloud版本升级教程
- 第43课 最大公约数 动动脑 第2题《小学生C++趣味编程》
- linux kvm服务,Linux-让Kvm虚拟机开放服务端口!
- 解读鸿蒙轻内核的监控器:异常钩子函数
- python学习笔记之property
- [Ext JS] 组件浮动一篇通(floating、alignTo)
- CCF NOI1028 判断互质
- 万能平板刷机软件_平板电脑怎么刷机 平板电脑刷机方法【教程】
- 好用的BUS调试工具-Bus Hound
- python面向对象练习题
- 8、共射放大电路一般性质与放大电路的直流偏移
- js initialize
- php php_sapi cli,php_sapi_name() cli
- 猫眼电影Top100爬取
- 如何使用kodi Mac安装中文插件
- Matlab画圆方向图,如何在matlab里画天线的立体方向图?
- 【分治算法】大整数乘法
- java画图板之平面山水画(一)
- 如何查看浏览器http请求协议