CodeForces Round #558 Div.2

Posted zlrrrr

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces Round #558 Div.2相关的知识,希望对你有一定的参考价值。

A. Eating Soup

技术图片
#include <bits/stdc++.h>
using namespace std;

int N, M;

int main() {
    scanf("%d%d", &N, &M);
    int ans;
    if(N == M) ans = 0;
    else if(M == 0 || M == 1 || M == N - 1) ans = 1;
    else {
         if(M <= N / 2) ans = M;
         else ans = N - M;
    }
    printf("%d\n", ans);
    return 0;
}
View Code

B1. Cat Party (Easy Edition)

B2. Cat Party (Hard Edition)

技术图片
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5 + 10;
int N;
int a[maxn];
map<int, int> mp;
map<int, int> cnt;

int main() {
    scanf("%d", &N);
    int ans = 0, maxx = -1, vis = 0;
    int flag = -1;

    for(int i = 1; i <= N; i ++) {
        scanf("%d", &a[i]);
        if(mp[a[i]] == 0) vis ++;
        cnt[mp[a[i]]] --;
        mp[a[i]] ++;
        cnt[mp[a[i]]] ++;
        maxx = max(maxx, mp[a[i]]);

        if(vis - 1 == cnt[maxx - 1] && cnt[maxx] == 1)
            ans = i, flag = 1;
        if(vis == cnt[1]) ans = i + 1, flag = 2;
        if(cnt[1] == 1 && cnt[maxx] == vis - 1) ans = i, flag = 3;
    }

    ans = min(N, ans);
    printf("%d\n", ans);
    return 0;
}
View Code

读题读错白白抑郁一天 今天可能写了史上最 lao 的 bug 我为什么还要把它给 FH 看???

以上是关于CodeForces Round #558 Div.2的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #558 (Div. 2)-Cat Party (Hard Edition)-(前缀和 + 模拟)

Codeforces Round #705 (Div. 2)

Codeforces Round #774 (Div. 2)

Codeforces Round #808 (Div. 1)(A~C)

Codeforces Round #717 (Div. 2)

Codeforces Round #784 (Div. 4)