HUD 1029Ignatius and the Princess IV

原题链接:[kuangbin带你飞]专题十二 基础DP1
B - Ignatius and the Princess IV

题意:

第一行输入n,表示有n个元素 n小于一百万
第二行输入n个元素
输出n个元素中出现次数大于二分之n的元素

思路

打表

#include"stdafx.h"
#include 
#include
#include 
#include 
using namespace std;

int n, t, ans;
int a[1000000];
int main()
{
    while (~scanf("%d", &n))
    {
        memset(a, 0, sizeof(a));
        ans = t  = 0;
        for (int i = 0; i < n; i++)
        {
            scanf("%d", &t);
            a[t]++;
            if (a[t] == (n + 1) / 2)
            {
                ans = t;
            }
        }
        printf("%d\n", ans);
    }
}


你可能感兴趣的:(HDU)