博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
K - Ignatius and the Princess IV
阅读量:5967 次
发布时间:2019-06-19

本文共 1708 字,大约阅读时间需要 5 分钟。

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
 
 
 
1 #include 
2 #include
3 using namespace std; 4 int s[1000000]; 5 int main() 6 { 7 int n; 8 while(cin>>n){ 9 int j,max,a,t;10 memset(s,0,sizeof(s));11 for(int i=0;i
>a;13 s[a]++;14 if(s[a]==(n+1)/2){15 t=a;16 }17 }18 cout<
<

 

转载于:https://www.cnblogs.com/farewell-farewell/p/5167264.html

你可能感兴趣的文章
poj - 1860 Currency Exchange
查看>>
chgrp命令
查看>>
Java集合框架GS Collections具体解释
查看>>
洛谷 P2486 BZOJ 2243 [SDOI2011]染色
查看>>
数值积分中的辛普森方法及其误差估计
查看>>
Web service (一) 原理和项目开发实战
查看>>
跑带宽度多少合适_跑步机选购跑带要多宽,你的身体早就告诉你了
查看>>
深入理解Java的接口和抽象类
查看>>
Javascript异步数据的同步处理方法
查看>>
iis6 zencart1.39 伪静态规则
查看>>
SQL Server代理(3/12):代理警报和操作员
查看>>
Linux备份ifcfg-eth0文件导致的网络故障问题
查看>>
2018年尾总结——稳中成长
查看>>
JFreeChart开发_用JFreeChart增强JSP报表的用户体验
查看>>
度量时间差
查看>>
通过jsp请求Servlet来操作HBASE
查看>>
Shell编程基础
查看>>
Shell之Sed常用用法
查看>>
<气场>读书笔记
查看>>
Centos下基于Hadoop安装Spark(分布式)
查看>>