Ignatius and the Princess IV
来源:互联网 发布:淘宝上的iphone6s 编辑:程序博客网 时间:2024/06/05 11:08
点击打开链接
"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
有好多种做法;
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[1000000];int main(){int n,m,max;while(scanf("%d",&n)!=EOF){ memset(a,0,sizeof(a));for(int i=0;i<n;i++){scanf("%d",&m);a[m]++;if(a[m]>=((n+1)/2))max=m;}printf("%d\n",max);}}
阅读全文
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
- Xamrin.Forms 基础——Behaviors——介绍
- 编译器
- linux中的genewise安装
- Android UI 线程操作
- 特征工程完全总结(Python源码)
- Ignatius and the Princess IV
- angular 自定义指令详解 Directive
- 长难句杂记(持续更新)
- Xamrin.Forms 基础——Behaviors——Attached Behaviors
- C/C++-STL中lower_bound与upper_bound的用法
- 60分钟精通正则表达式
- Reversible Primes
- JAVA基本运行顺序
- Ubuntu16.04下安装VS Code