Ignatius and the Princess IV
来源:互联网 发布:素质测评软件 编辑:程序博客网 时间:2024/05/19 04:56
"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这道题简单的我都会做啊,排序后输出(n+1)/2的值就好
#include<cstdio>#include<vector>#include<algorithm>using namespace std;#define maxx 1000000+10int a[maxx];int main(){int n;while(scanf("%d",&n)!=EOF){for(int i = 0 ; i < n ; i++)scanf("%d",&a[i]);sort(a,a+n);printf("%d\n",a[n/2]);}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
- 微信小程序把玩(三十七)location API
- hdu4258Covered Walkway(斜率)
- MVC简介及优缺点
- python—pandas中DataFrame类型数据操作函数
- Python读写csv小白指南
- Ignatius and the Princess IV
- Deeplearning4j源码研习(1): BP算法原理及源码实现
- POJ 1067 取石子游戏 经典威佐夫博弈
- 《Spring+Mybatis企业应用实战》学习-1~3章
- LinkedHashMap
- 数据结构串的基本操作及KMP算法
- 将Behavior插件和AStarPathFinding插件结合
- Example3.12 Solving the Gridworld
- js多态直观理解