寻找出现频率最高的数【杭电-1029 】附题
来源:互联网 发布:python bytesio 编辑:程序博客网 时间:2024/06/14 00:01
/*
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 16604 Accepted Submission(s): 6665
Problem 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
*/
#include<stdio.h> //该题难点在于:需理解要输出的数>=(N+1)/2
int main()
{
int n,i,j,k,a;
while(scanf("%d",&n)!= EOF){
a=0;
for(i=0;i<n;++i){
scanf("%d",&j);
if(a==0) k=j,++a;
else j == k ? ++a : --a;
}
printf("%d\n",k);
} return 0;
}
- 寻找出现频率最高的数【杭电-1029 】附题
- 寻找出现频率超过一半的数
- 寻找出现频率超过一半的数
- 寻找出现频率超过一半的数
- 出现频率最高的笔试题
- 出现频率最高的笔试题
- 出现频率最高的笔试题
- 出现频率最高的笔试题
- c++求数组中出现频率最高的数
- 出现频率最高的笔试题strcpy写法
- c函数:出现频率最高的笔试题strcpy写法
- 出现频率最高的笔试题strcpy写法
- 出现频率最高的笔试题strcpy写法- -
- 出现频率最高的笔试题strcpy写法
- 出现频率最高的笔试题strcpy用法
- 出现频率最高的笔试题strcpy写法
- 出现频率最高的笔试题strcpy写法
- 出现频率最高的笔试题strcpy写法
- Mybatis+strus2+spring 整合
- 生活
- 大视野1503-- [NOI2004]郁闷的出纳员SPLAY
- Eclipse自动生成Getter,Setter和构造方法
- iOS开发笔记之二——XCTest单元测试框架的使用
- 寻找出现频率最高的数【杭电-1029 】附题
- 【数据结构】迷宫搜索
- Linux内核剖析 之 内存寻址(二)
- 管理寓言之四:“热炉”法则
- hadoop2.4.1启动时候warning
- 超声波模块SRF05
- 第145天
- 很多人说SEO是忽悠,大牛们都放弃SEO行业?
- 管理寓言之五:“刺猬”法则