首页 > 其他 > 详细

Hdu oj 1029 Ignatius and the Princess IV

时间:2015-08-15 13:33:06      阅读:166      评论:0      收藏:0      [点我收藏+]

题目:点击打开链接

代码一:

#include<stdio.h>
#include<string.h>
int b1[1000000];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int i;
		int a,t;
		memset(b1,0,sizeof(b1));
		for(i=0;i<n;i++)
		{
			scanf("%d",&a);
			b1[a]++; 
			if(b1[a]>=(n+1)/2)
			t=a;
		}
	    printf("%d\n",t);
	    
	}
	return 0;
}


代码二:

#include<stdio.h>
#include<string.h>
int b1[1000000];
int main()
{
	int n;
	while(~scanf("%d",&n))
	{
		int i;
		int a;
		memset(b1,0,sizeof(b1));
		for(i=0;i<n;i++)
		{
			scanf("%d",&a);
			b1[a]++; 
		}
		for(i=0;i<1000000;i++)//晕,刚开始开到n, wrong answer 
		{
			if(b1[i]>=(n+1)/2)
			{
			    break;
			}
		}
		printf("%d\n",i);
	}
	return 0;
}


 

版权声明:本文为博主原创文章,未经博主允许不得转载。

Hdu oj 1029 Ignatius and the Princess IV

原文:http://blog.csdn.net/zm_11/article/details/47680813

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!