zoukankan      html  css  js  c++  java
  • B2. Cat Party (Hard Edition)

    题目链接:

    https://codeforces.com/problemset/problem/1163/B2

    题目大意:

    有n个点,然后每个点都有一个颜色,然后找到一个最大的坐标,能够满足:从1 ~ i 这个位置,我们可以任意删除一个人,使得剩下的所有的颜色出现次数都相等。

    具体思路:

    SB模拟题给打残了。。。

    满足题目条件的有如下四种情况:

    1,都只出现过一次

    2,从1~i都是相同的数

    3,出现了一次的有一个,剩下的出现次数都相同。

    4,当前局势 有出现不同次数的有两种情况,比如果 出现了a次的和出现了b次的,因为我们要删除一个人,所以一定是删除出现次数多的那个(删除出现少的时候,只有次数为1的时候满足,次数为1的已经判断好了)。所以我们判断当前出现次数多的-1 去乘以当前次数减去1的个数是不是等于 i - 出现次数最多的个数  就好了。

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 # define ll long long
     4 const int maxn = 2e5+100;
     5 map<int,int>cnt;
     6 map<int,int>sum;
     7 int main(){
     8 int n,tmp;
     9 scanf("%d",&n);
    10 int maxx=0,ans=0;
    11 for(int i=1;i<=n;i++){
    12 scanf("%d",&tmp);
    13 cnt[tmp]++;
    14 sum[cnt[tmp]-1]--;
    15 sum[cnt[tmp]]++;
    16 maxx=max(maxx,cnt[tmp]);
    17 if(i==sum[1]){ans=max(ans,i);}
    18 if(sum[i]==1){ans=max(ans,i);}
    19 if(sum[1]==1&&maxx*sum[maxx] == i - 1){ans=max(ans,i);}
    20 if(sum[maxx] == 1 && ( sum[maxx-1]*(maxx-1)== i - maxx ) ){ans=max(ans,i);}
    21 }
    22 printf("%d
    ",ans);
    23 return 0;
    24 }
  • 相关阅读:
    CF919F A Game With Numbers
    CF1005F Berland and the Shortest Paths
    CF915F Imbalance Value of a Tree
    CF1027F Session in BSU
    CF1029E Tree with Small Distances
    CF1037E Trips
    CF508E Arthur and Brackets
    CF1042F Leaf Sets
    [HNOI2012]永无乡
    [BZOJ1688][Usaco2005 Open]Disease Manangement 疾病管理
  • 原文地址:https://www.cnblogs.com/letlifestop/p/10921300.html
Copyright © 2011-2022 走看看