hdu 1029 Ignatius and the Princess IV 动态规划
来源:互联网 发布:远程迅雷 linux 编辑:程序博客网 时间:2024/06/03 08:21
Ignatius and the Princess IV
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32767 K (Java/Others)Total Submission(s): 22439 Accepted Submission(s): 9395
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
Recommend
We have carefully selected several similar problems for you: 1040 1074 1028 1171 1203
n是一个奇数,找出这n个数中出现至少(n+1)/2 次 的数。
经多思考,要利用这个数出现次数多的特性。
#include<cstdio>#include<string>#include<cstring>#include<iostream>#include<cmath>#include<algorithm>#include<climits>#include<queue>#include<vector>#include<map>#include<sstream>#include<set>#include<stack>#include<cctype>#include<utility>#pragma comment(linker, "/STACK:102400000,102400000")#define PI 3.1415926535897932384626#define eps 1e-10#define sqr(x) ((x)*(x))#define FOR0(i,n) for(int i=0 ;i<(n) ;i++)#define FOR1(i,n) for(int i=1 ;i<=(n) ;i++)#define FORD(i,n) for(int i=(n) ;i>=0 ;i--)#define lson num<<1,le,mid#define rson num<<1|1,mid+1,ri#define MID int mid=(le+ri)>>1#define zero(x)((x>0? x:-x)<1e-15)#define mk make_pair#define _f first#define _s secondusing namespace std;//const int INF= ;typedef long long ll;//const ll inf =1000000000000000;//1e15;//ifstream fin("input.txt");//ofstream fout("output.txt");//fin.close();//fout.close();//freopen("a.in","r",stdin);//freopen("a.out","w",stdout);const int INF =0x3f3f3f3f;//const int maxn= ;//const int maxm= ;int n;int main(){ int x; int now,cnt; while(~scanf("%d",&n ) ) { cnt=0; for(int i=1;i<=n;i++) { scanf("%d",&x); if(cnt==0) {cnt++;now=x ;} else { if(now!=x) cnt--; else cnt++; }//一开始,想当然,没有判断x是否=now,真是低级错误。 } printf("%d\n",now); } 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
- 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
- CheckBox 实现简单的点击开关控制
- struts2知识点
- C语言中的算术运算符和算术表达式
- python中 tab 键自动补全
- HashMap Hashtable区别
- hdu 1029 Ignatius and the Princess IV 动态规划
- 在tomcat上发布一个javaweb项目
- OpenJudge NOI题库 6266:取石子游戏
- Java+MySQL实现网络爬虫程序
- verilog 有符号数(2转)
- 如何开发一个Server-Client模型的程序
- tail 命令
- HDU 5531 Rebuild ——— 2015ACM-ICPC亚洲区长春站
- Nginx服务器的概念