Vasya and Multisets - codeforce

ps:没想清楚就码代码是很危险的!还有要仔细审题,其中一个集合是可以空集的。

int n;
int a[200], cnt[200];

int main()
{
    cin >> n;
    Rep(i, 1, n) {
        cin >> a[i];
        cnt[a[i]]++;
    }
    int t1 = 0, t2 = 0, t3 = 0;
    Rep(i, 1, 100) {
        if (cnt[i] == 1) t1++;
        else if (cnt[i] == 2) t2++;
        else if (cnt[i] > 2) t3++;
    }
    if ((t1 & 1) && (!t3)) {
        puts("NO");
        return 0;
    }
    puts("YES");

    char ans[200];
    Rep(i, 1, 100) ans[i] = 'A';

    int s = 0;
    Rep(i, 1, n) if (cnt[a[i]] == 1) {
        s++;
        ans[i] = (s & 1 ? 'A' : 'B');
    }

    if (t1 & 1) Rep(i, 1, n) if (cnt[a[i]] > 2) {
        ans[i] = 'B';
        break;
    }

    Rep(i, 1, n) cout << ans[i];
    cout << endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/zgglj-com/p/9687930.html
今日推荐