Ignatius and the Princess IV
2016-05-25 14:01
543 查看
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=68966#problem/B
Ignatius and the Princess IV
Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice HDU
1029
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
(n+1)/2的个数永远是最多的,就算两个两个去,最后剩下来的那个也是ans
/* ***********************************************
Author :Lu_cky
Created Time :2016年05月25日 星期三 13时47分06秒
File Name :main.cpp
************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int SIZE=1e6+10;
const int maxn=1<<30;
int a[SIZE];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
while(scanf("%d",&n)!=EOF){
int ans,time=0,x;
for(int i=0;i<n;i++){
scanf("%d",&x);
if(time==0){
ans=x;
time++;
}
else if(ans==x)time++;
else time--;
}
printf("%d\n",ans);
}
return 0;
}
Ignatius and the Princess IV
Time Limit:1000MS Memory Limit:32767KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice HDU
1029
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
(n+1)/2的个数永远是最多的,就算两个两个去,最后剩下来的那个也是ans
/* ***********************************************
Author :Lu_cky
Created Time :2016年05月25日 星期三 13时47分06秒
File Name :main.cpp
************************************************ */
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
const int SIZE=1e6+10;
const int maxn=1<<30;
int a[SIZE];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
while(scanf("%d",&n)!=EOF){
int ans,time=0,x;
for(int i=0;i<n;i++){
scanf("%d",&x);
if(time==0){
ans=x;
time++;
}
else if(ans==x)time++;
else time--;
}
printf("%d\n",ans);
}
return 0;
}
相关文章推荐
- HttpSessionAttributeListener
- Java小程序:辗除法求两个正整数最大公约数和最小公倍数
- hihoCoder 1061 Beautiful String
- 正则表达式获取URL参数
- socket编程:简单UDP服务器/客户端编程
- C++之动态空间分配与释放:new & delete
- 韩顺平Spring框架学习,学习笔记(八)
- Hibernate 单向一对多配置以及增删改查
- Android 判断SD卡是否存在及容量查询
- SQL模糊查询
- VC++异常处理
- AngularJs学习笔记(二) 指令directive
- Linux chattr/lsattr
- Octave 线性代数 行列式 4
- hdu2092 整数解
- C++异常处理
- GStreamer基础教程02——GStreamer概念
- linux fuse文件系统在 android fuse sdcard的 运用
- Cas(5)-修改Cas Server的其它配置
- 使用apache的ab工具做压力测试