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
", 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
", ans);
    return 0;
}
View Code

 

原文地址:https://www.cnblogs.com/zlrrrr/p/10908880.html