HUD 1029Ignatius and the Princess IV

来源:互联网 发布:资源数据库建设 编辑:程序博客网 时间:2024/05/02 03:02

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

题意:

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

思路

打表

#include"stdafx.h"#include <iostream>#include<cstdio>#include <algorithm>#include <cstring>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);    }}
0 0
原创粉丝点击