CF558 B2 Cat Party (Easy Edition)

题意:

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

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

 

非常好的逻辑题

#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

转载于:https://www.cnblogs.com/bxd123/p/10842938.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值