题意:

给出一串数字    要求求出最大的x  

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

然后读取前x个数字   在其中去掉一个数字(必须是一个)使得所有元素出现次数相同!!

 

非常好的逻辑题

CF558 B2 Cat Party (Easy Edition) 随笔 第1张
#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define pb push_back
#define REP(i,N)  for(int i=0;i<(N);i++)
#define CLR(A,v)  memset(A,v,sizeof A)
//////////////////////////////////
#define inf 0x3f3f3f3f
#define lson l,m,pos<<1
#define rson m+1,r,pos<<1|1
const int N=400000+5;
int cnt[N],f[N];
int color,mx;

int main()
{
    int n;RI(n);
    int ans=1;
    rep(i,1,n)
    {
        RI(color);
        cnt[ f[color] ]--;
        f[color]++;
        cnt[ f[color] ]++;

         mx=max(mx,f[color]);
        bool ok=0;

        if(cnt[1]==i)//全为1  出现1次的有i个
        ok=1;
        else if(cnt[i]==1)//所有元素相同  出现i次的有一个
        ok=1;
        else if(cnt[1]==1&&i-1==mx*cnt[mx] )//一个元素出现次数为1  其他相等
        ok=1;
        else if(cnt[mx]==1&& i-mx==cnt[mx-1]*(mx-1)   )
        ok=1;
        if(ok)
            ans=i;
    }
    cout<<ans;

    return 0;
}
View Code
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄