Ignatius and the Princess IV
来源:互联网 发布:2013nba东部决赛数据 编辑:程序博客网 时间:2024/06/18 07:23
"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?
"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?
51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1
351
要认真思考,其实出现次数大于(n+1)/2 的只有一个!!!!
判断一下就行了。
#include <iostream>#include <cstdio>#include <cstring>const int MAX=1e6+10;int sum[MAX];int main(){ int n; while(~scanf("%d",&n)) { int x,max = 0; for(int i = 1 ; i <= n ; i++) { scanf("%d",&x); sum[x]++; if(sum[x] >= (n+1)/2) max = x;}printf("%d\n",max);memset(sum, 0 , sizeof(sum));}return 0; }
阅读全文
0 0
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Ignatius and the Princess IV
- Unity 5.x UGUI 控件使用
- HyperLedger/fabric1.0.0正式版安装部署
- ActionContext.getContext()的基本用法
- lambda表达式及3个内置函数
- Python 随机生成200个优惠码
- Ignatius and the Princess IV
- Common Subsequence||HDU1159
- RocketMQ存储篇——MapedFileQueue
- 小程序-初学篇
- 面试题55. 表示数值的字符串
- [Mark] python 聚类分析 kmeans() 函数使用时报错
- [RK3288][Android6.0] 调试笔记 --- pmu(rk818)寄存器读写
- 网易校招编程题之藏宝图
- 关键字的作用及区别汇总