只是說統計出現超過n+1/2 的數字 和編程之美上的發帖水王 類似的解法
http://acm.hdu.edu.cn/showproblem.php?pid=1029
#include<iostream>
int main()
{
int i,n,num,currnum,ans;
while(scanf("%d",&n)!=EOF)
{
scanf("%d",&num);
currnum = num;
ans = 1;
for(i = 1 ; i < n; i ++)
{
scanf("%d",&num);
if(ans == 0)
currnum = num,ans ++;
else if(num != currnum)
{
ans --;
}
else if (num == currnum)
ans ++;
}
printf("%d\n",currnum);
}
return 0;
}
posted on 2010-06-01 22:46
付翔 閱讀(303)
評論(0) 編輯 收藏 引用 所屬分類:
ACM 數據結構