首页 > 其他 > 详细

HDU 1029 Ignatius and the Princess IV

时间:2015-04-23 15:44:32      阅读:171      评论:0      收藏:0      [点我收藏+]

水题啊,说好的dp呢

刚开始的想法是hash,但题目数据范围没给出来。一直在想怎么用dp

然后看了看解题报告,解法太简单了,因为一定有某数出现次数比其他所有的数出现次数加起来都大,所以用个计数器互相抵消就可以了。

#include<stdio.h>
int main(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	int n;
	while(scanf("%d",&n)!=EOF){
		int num,cnt=0,ans;
		while(n--){
			scanf("%d",&num);
			if(cnt==0){
				ans=num;
				cnt++;
			}
			else{
				if(ans==num) cnt++;
				else cnt--;
			}
		}
		printf("%d\n",ans);
	}
}


HDU 1029 Ignatius and the Princess IV

原文:http://blog.csdn.net/lj94093/article/details/45221287

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