hdu-1029 Ignatius and the Princess IV
题目链接:
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
"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?
# 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相关推荐
- HDU - 1029 Ignatius and the Princess IV
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=1029 题目大意 给你n(n为奇数, n < 1e6)个数,让你找到个数 >=( ...
- Hdu 1029 Ignatius and the Princess IV
思路:普通的cin会超时 方法很妙 1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 ...
- 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 1026 Ignatius and the Princess I(BFS)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1026 在这博客学的 ttp://www.wutianqi.com/?p=2354 感觉看了这个之后收获 ...
- 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 ...
- HDU1029 - Ignatius and the Princess IV【水题】
给你n个数字,请你找出出现至少(n+1)/2次的数字. 输入 本题包含多组数据,请处理到EOF: 每组数据包含两行. 第一行一个数字N(1<=N<=999999) ,保证N为奇数. 第二行 ...
- HDU 1026 Ignatius and the Princess I 迷宫范围内的搜索剪枝问题
这个问题是一个典型的类型的问题迷宫广泛的搜索. 在网上看到了很多解决方案. 没什么解决问题的分析报告,不指出其中的关键点.代码更像是一大抄.一些分析师也有很大的文章分析.只是不要全部命中关键,什么是广 ...
- hdu 1026 Ignatius and the Princess I(优先队列+bfs+记录路径)
以前写的题了,现在想整理一下,就挂出来了. 题意比较明确,给一张n*m的地图,从左上角(0, 0)走到右下角(n-1, m-1). 'X'为墙,'.'为路,数字为怪物.墙不能走,路花1s经过,怪物需要 ...
- 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 ...
最新文章
- (转)解决在firefox下js调用as失败问题
- 计算机安全的最后一道防线,汪文勇:灾备,数据安全的最后一道防线
- 谈谈战双的战斗机制设计趋同
- Mysql数据库(一)——mysql数据库初体验
- 一篇文章带你熟悉 TCP/IP 协议(网络协议篇二)
- g100显卡 linux驱动,nvidia geforce g100驱动
- Eclipse / Spring Tool Suite 配置
- Hacker's Technique programme pdf+源码
- 医院计算机网络系统的现状,医院信息系统应用的现状与发展
- 用异常处理改编猜数游戏程序
- PES,TS,PS,RTP等流的打包格式解析之PES流
- 白帽黑客教主 TK 告诉你,黑客的游戏 CTF 究竟是什么 | 硬创公开课总结文+视频...
- 植物大战僵尸修改关卡及金币
- 阿里巴巴CTO行癫:阿里双11是世界互联网技术的超级工程
- 计算机网络实验六 综合设计实验
- ROS常用的仿真软件
- 什么是AppImage
- 非root执行php不输出,Linux下crond切换到非root用户不执行的问题解决方法
- 快手,字节跳动,百度,美团Offer之旅(Android面经分享)
- 《点燃我,温暖你》李峋 代码 爱心❤ - 源代码
热门文章
- 第二阶段个人总结06
- 【译】为什么这样宏定义#define INT_MIN (-2147483647 - 1)?
- Python学习入门基础教程(learning Python)--1.4 Python数据处理基础 .
- sniffer使用查网络故障
- opencv利用直方图判断人脸光照质量
- shell中$后加引号有什么用($string和$'string')
- 【Python】Python 过滤列表
- spring与springMVC配置扫描的问题
- 分布式系统架构知识储备
- 从Folly源码学C++ 11的新特性