BZOJ 2456 mode (look for the mode) (summer ACM1 F)

The meaning of problems

To the number n, find the highest number of number appears, ensure the emergence of n / 2 times.

100% data, n <= 500000, the number of columns in each of the number of <= maxlongint.

answer

The idea is normal fast row, then statistical answer.

But this question only pit to pit in memory 1M, so the array is not even able to open.

So there is a fairy practice, and since there is the n / 2, then the other number add up to dry, but him.

So we record sum for the current number of remaining public life [funny], ans current congregation numbers, if this time the read count is the number of the congregation, he can eat mouth medicine, then we should not suffer a drop of blood was beaten [hurts], if no blood we will have another warrior to resist, to the last station is the Chosen One (the mode).

But the current ans is not the final answer, others attack him affect you?

Of course not, they kill each other, get comfortable on the mode for a group, you can use less blood to get them.

Simply wonderful ah, HFU said it was a simple question, and 1 + 1, as this is likely to sxk

#include<cstdio>
using namespace std;
int n,ans,sum=0,x;
int main()
{
    
    scanf("%d",&n); 
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&x);
        if(!sum) {ans=x;++sum;}
        else
        {
            if(x==ans) ++sum;
            else --sum;
        }
    }
    printf("%d",ans);
    return 0;
}
View Code

There are universal head accounted for more memory

Guess you like

Origin www.cnblogs.com/sto324/p/11222280.html