zoukankan      html  css  js  c++  java
  • HDU 1029 Ignatius and the Princess IV

    题意:找出n个数内出现次数大于n/2的数,并且输出。

    分析:如果前m个数内,一个数出现了m/2次,那么删掉这m个数不会对结果造成影响。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    
    using namespace std;
    
    int a[1000000];
    
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            for(int i=1; i<=n; i++)
            {
                scanf("%d",&a[i]);
            }
            int num,sum=0;
            for(int i=1; i<=n; i++)
            {
                if(sum==0)
                {
                    num=a[i];
                    sum=1;
                }
                else
                {
                    if(num==a[i])
                        sum++;
                    else
                        sum--;
                }
            }
            printf("%d
    ",num);
        }
    
        return 0;
    }
  • 相关阅读:
    bzoj1098 1301
    bzoj3237
    bzoj3170
    bzoj4008
    一些题解
    bzoj4028
    bzoj3196
    redis学习
    quartz学习
    电商618 压测、优化、降级预案
  • 原文地址:https://www.cnblogs.com/mengzhong/p/4934059.html
Copyright © 2011-2022 走看看