标签:水题
水题啊,说好的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