Ignatius and the Princess IV

    xiaoxiao2025-10-20  8

    题意:给出一个奇数n,再给出n个数,求出现了至少(n+1)/2次的那个数。(反正不会出现两个以上)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=1175

    代码:

    #include <cstdio> #include <cstring> const int maxn = 1e6; int vis[maxn]; int main() { int n; while (scanf("%d", &n) != EOF) { int a,k; memset(vis, 0, sizeof(vis)); for(int i=0; i<n; i++) { scanf("%d", &a); vis[a]++; if (vis[a] == (n+1)/2) k = a; } printf("%d\n", k); } return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1303360.html
    最新回复(0)