题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1029

题目类型:

给一个奇数个列的数组,其中一定存在某个数字,该数字的个数是大于一半的,问这个数字是几

解题思路:

1、sort一遍,直接输出下标为n/2的数。

2、将数组开为1000010,然后将数组置0,读入一个数,下标为该数的数值+1,最后进行一次循环,判断那个数值最大,输出即可。(当年还不会快排所以用的这个方法,亲测AC)。

题目:

Ignatius and the Princess IV

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 31704    Accepted Submission(s): 13646

Problem Description
"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.

"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.

"But what is the characteristic of the special integer?" Ignatius asks.

"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.

Can you find the special integer for Ignatius?

Input
The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.
Output
For each test case, you have to output only one line which contains the special number you have found.
Sample Input
5 1 3 2 3 3 11 1 1 1 1 1 5 5 5 5 5 5 7 1 1 1 1 1 1 1
Sample Output
3 5 1
# include <stdio.h>
# include <string.h>
# define N 1000010
int n,a[N],b[N];int main ()
{int i,ret,max;while(scanf("%d",&n)!=EOF){memset(b,0,sizeof(b));max=0; ret=0;for(i=0;i<n;i++){scanf("%d",&a[i]);b[a[i]]++;if(b[a[i]] >max){max=b[a[i]];ret=a[i];}}printf("%d\n",ret);    }return 0;
}

转载于:https://www.cnblogs.com/love-sherry/p/6941505.html

hdu-1029 Ignatius and the Princess IV相关推荐

  1. HDU - 1029 Ignatius and the Princess IV

    题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=1029 题目大意 给你n(n为奇数, n < 1e6)个数,让你找到个数 >=( ...

  2. Hdu 1029 Ignatius and the Princess IV

    思路:普通的cin会超时 方法很妙 1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 ...

  3. 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 ...

  4. HDU 1026 Ignatius and the Princess I(BFS)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 在这博客学的 ttp://www.wutianqi.com/?p=2354 感觉看了这个之后收获 ...

  5. hdu 1398 Square Coins/hdu 1028 Ignatius and the Princess III

    两道母函数的模板题: http://acm.hdu.edu.cn/showproblem.php?pid=1398 View Code #include<iostream>#include ...

  6. HDU1029 - Ignatius and the Princess IV【水题】

    给你n个数字,请你找出出现至少(n+1)/2次的数字. 输入 本题包含多组数据,请处理到EOF: 每组数据包含两行. 第一行一个数字N(1<=N<=999999) ,保证N为奇数. 第二行 ...

  7. HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题

    这个问题是一个典型的类型的问题迷宫广泛的搜索. 在网上看到了很多解决方案. 没什么解决问题的分析报告,不指出其中的关键点.代码更像是一大抄.一些分析师也有很大的文章分析.只是不要全部命中关键,什么是广 ...

  8. hdu 1026 Ignatius and the Princess I(优先队列+bfs+记录路径)

    以前写的题了,现在想整理一下,就挂出来了. 题意比较明确,给一张n*m的地图,从左上角(0, 0)走到右下角(n-1, m-1). 'X'为墙,'.'为路,数字为怪物.墙不能走,路花1s经过,怪物需要 ...

  9. HDU 1028 Ignatius and the Princess III

    //强行递推. xx[i][j]表示i数中第j个开头的组合种类. /* 最终结果[i]为 sum of(xx[i][j])  (j from 1  to i); xx[i][j]=sum of (xx ...

最新文章

  1. (转)解决在firefox下js调用as失败问题
  2. 计算机安全的最后一道防线,汪文勇:灾备,数据安全的最后一道防线
  3. 谈谈战双的战斗机制设计趋同
  4. Mysql数据库(一)——mysql数据库初体验
  5. 一篇文章带你熟悉 TCP/IP 协议(网络协议篇二)
  6. g100显卡 linux驱动,nvidia geforce g100驱动
  7. Eclipse / Spring Tool Suite 配置
  8. Hacker's Technique programme pdf+源码
  9. 医院计算机网络系统的现状,医院信息系统应用的现状与发展
  10. 用异常处理改编猜数游戏程序
  11. PES,TS,PS,RTP等流的打包格式解析之PES流
  12. 白帽黑客教主 TK 告诉你,黑客的游戏 CTF 究竟是什么 | 硬创公开课总结文+视频...
  13. 植物大战僵尸修改关卡及金币
  14. 阿里巴巴CTO行癫:阿里双11是世界互联网技术的超级工程
  15. 计算机网络实验六 综合设计实验
  16. ROS常用的仿真软件
  17. 什么是AppImage
  18. 非root执行php不输出,Linux下crond切换到非root用户不执行的问题解决方法
  19. 快手,字节跳动,百度,美团Offer之旅(Android面经分享)
  20. 《点燃我,温暖你》李峋 代码 爱心❤ - 源代码

热门文章

  1. 第二阶段个人总结06
  2. 【译】为什么这样宏定义#define INT_MIN (-2147483647 - 1)?
  3. Python学习入门基础教程(learning Python)--1.4 Python数据处理基础 .
  4. sniffer使用查网络故障
  5. opencv利用直方图判断人脸光照质量
  6. shell中$后加引号有什么用($string和$'string')
  7. 【Python】Python 过滤列表
  8. spring与springMVC配置扫描的问题
  9. 分布式系统架构知识储备
  10. 从Folly源码学C++ 11的新特性