【HDU1029】B
来源:互联网 发布:如何将照片导入mac 编辑:程序博客网 时间:2024/06/05 22:50
这里是题目
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)
Total Submission(s): 33781 Accepted Submission(s): 14627
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>#include<algorithm>using namespace std;int a[1000000];int main(){ int m,n; while(~scanf("%d",&n)) { int t=1,k,i,j; for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); //排序,相同的就会在一起了 for(i=0;i<n;i++) { if(a[i]==a[i+1]) { t++; if(t==(n+1)/2) { m=a[i]; break; } } else { t=1; continue; } } printf("%d\n",m); }return 0;}
- 【HDU1029】B
- hdu1029
- HDU1029
- hdu1029
- hdu1029
- hdu1029
- hdu1029
- HDU1029
- HDU1029
- HDU1029
- hdu1029 B - Ignatius and the Princess IV
- HDU1029 水题
- hdu1029 技巧
- hdu1029(基础)
- HDU1029时钟(排序)
- HDU1029 False coin
- HDU1029(水)
- HDU1029 找中间数
- leetcode[Keyboard Row]//待整理多种解法
- HTTPS为什么安全 &分析 HTTPS 连接建立全过程
- 算法预备军(4)~树的概念
- debian版本升级
- Atitit.每周末总结 于每周一计划日程表 流程表 v8 -------------import 上周遗漏日志补充 检查话费 检查流量情况 Crm问候 Crm表total and 问候
- 【HDU1029】B
- 需求管理三步法
- Volley原理和Okhttp原理
- FTP学习1_FTP命令字和响应码解释
- Python 之study
- 09springmvc异常处理-抛出异常-异常测试
- 嵌入式每日学习心得2017.08.07
- Go语言学习笔记 --- slice切片
- python爬虫04