您的位置:首页 > 其它

HDU 1029 Ignatius and the Princess IV(水题)

2016-10-26 22:53 375 查看
题意:给N个数,输出这N个数中出现至少(N+1)/2次的数.

#include<iostream>
using namespace std;
__int64 num[1000000];//感觉可以开得更小点。数据挺弱的
int main()
{
int n;
while(~scanf("%d", &n))
{
int k=(n+1)/2,x, ans;
while(n--)
{
scanf("%d", &x);
num[x]++;
if(num[x]>=k) ans=x;
}
printf("%d\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: