【HDOJ】1029 -> Ignatius and the Princess IV

来源:互联网 发布:极限矩阵一体机 编辑:程序博客网 时间:2024/04/30 20:41

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1029

心得:

        通常可以用a[index]=k表示数字index重复的次数为k。

代码:

#include <iostream>using namespace std; const int MAX=500000;int a[MAX];int main(){int n,x,i,id;while(cin>>n){memset(a,0,sizeof(a));for(i=0;i<n;i++){cin>>x;a[x]++;if(a[x]>=(n+1)/2){id=x;}}cout<<id<<endl;}return 0;}

原创粉丝点击