hdu 1029 ( Ignatius and the Princess IV ) 水题

#include<iostream>
#include<algorithm>
using namespace std;
int
i,n,j,p,w,a[1000000],ans[1000000];
int
main()
{

    while
(scanf("%d",&n)!=EOF)
    {

        p=(n+1)/2;
        memset(ans,0,sizeof(ans));
        for
(j=0;j<n;j++)
            scanf("%d",&a[j]);
        for
(i=0;i<n;i++)
        {

            ans[a[i]]++;
            if
(ans[a[i]]>=p)
            {

                printf("%d\n",a[i]);
                break
;
            }
        }
    }

    return
0;
}

posted @ 2013-04-30 18:01  galaxy77  阅读(115)  评论(0编辑  收藏  举报