HDU 1029 Ignatius and the Princess IV【】
来源:互联网 发布:烟斗尺寸的基本数据 编辑:程序博客网 时间:2024/05/29 18:45
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 29097 Accepted Submission(s): 12336
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?
"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
51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1
Sample Output
351
Author
Ignatius.L
#include<cstdio>#include<cmath>#include<cstring>#include<climits>#include<string>#include<queue>#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<climits>#include<string>#include<queue>#include<stack>#include<set>#include<map>#include<algorithm>using namespace std;#define rep(i,j,k)for(i=j;i<k;i++)#define per(i,j,k)for(i=j;i>k;i--)#define MS(x,y)memset(x,y,sizeof(x))#define max(a,b) a>b?a:b#define min(a,b) a<b?a:b#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long LL;const int INF=0x7ffffff;#define lson rt<<1, l, m#define rson rt<<1|1, m+1, rconst int M=1e6+10;int num[M];int i,k,j,n,m,t;int a[M];int main(){ while(~scanf("%d",&n)){ int num=0; int max_; for(i=0;i<n;i++){ scanf("%d",&t); if(num==0){ max_=t; num++; } else { if(t==max_){ num++; } else num--; } } printf("%d\n",max_); } return 0;}
#include<cstdio>#include<cmath>#include<cstring>#include<climits>#include<string>#include<queue>#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<climits>#include<string>#include<queue>#include<stack>#include<set>#include<map>#include<algorithm>using namespace std;#define rep(i,j,k)for(i=j;i<k;i++)#define per(i,j,k)for(i=j;i>k;i--)#define MS(x,y)memset(x,y,sizeof(x))#define max(a,b) a>b?a:b#define min(a,b) a<b?a:b#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long LL;const int INF=0x7ffffff;#define lson rt<<1, l, m#define rson rt<<1|1, m+1, rconst int M=1e6+10;int num[M];int i,k,j,n,m;int a[M];int main(){ while(~scanf("%d",&n)) { for(i=0;i<n;i++){ scanf("%d",&a[i]); } sort(a,a+n); int max_=0; int tmp=0; int flag; for(i=0;i<n;i++){ if(a[i]!=a[i+1]){ tmp++; if(tmp>max_){ max_=tmp; if(max_>=(n+1)/2){flag=i;break;} } } else tmp++; } printf("%d\n",a[flag]); } return 0;}
0 0
- hdu 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- Ignatius and the Princess IV hdu 1029
- hdu 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- hdu 1029 Ignatius and the Princess IV
- HDU 1029 Ignatius and the Princess IV
- HDU-1029-Ignatius and the Princess IV
- HDU--1029--Ignatius and the Princess IV
- hdu - 1029 -Ignatius and the Princess IV
- 使用System.arraycopy()实现数组之间的复制
- 关于多线程程序中使用volatile关键字的一个小例子
- Zookeeper服务端架构
- SSAutoresizeLabelFlow实现多个label排列
- Bank Simulation Program银行管理系统C++ :)
- HDU 1029 Ignatius and the Princess IV【】
- c程序设计(4)函数课后习题
- 面试准备
- 51nod 1035 最长的循环节
- 20170120
- make工程管理器
- 001_Oracle数据库、SQL语言的介绍
- C++ I/O流常用控制符
- HDU1587-Flowers