codeforce1163B2. Cat Party (Hard Edition) Thinking

CF1163B2. Cat Party (Hard Edition) Thinking

Link: http://codeforces.com/contest/1163/problem/B2

The meaning of the question:
first give n
and then give an array of n numbers. It is
required to output a k. After satisfying the first k numbers, the number of each type is the same.
Output the maximum value of k.

Analysis: When
reading in, record the number of occurrences of each of the first n numbers + the number of occurrences of the number of occurrences
(look at the code directly, faster)

#include<iostream>
typedef long long ll;
using namespace std;
const int maxm=1e5+5;
int a[maxm];
int b[maxm];
int main()
{
    
    
    int n,ans=1;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    
    
        int t;
        cin>>t;
        a[t]++;
        b[a[t]]++;
        if(a[t]*b[a[t]]==i&&i!=n)
        {
    
    
            ans=i+1;
        }
        if(a[t]*b[a[t]]==i-1)
        {
    
    
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Guess you like

Origin blog.csdn.net/qq_40534166/article/details/97302569