码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1029 Ignatius and the Princess IV

时间:2015-04-23 15:46:21      阅读:173      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!