Educational Codeforces Round 51 (Rated for Div. 2) C. Vasya and Multisets(思路)

描述

Vasya has a multiset ss consisting of nn integer numbers. Vasya calls some number xx nice if it appears in the multiset exactly once. For example, multiset {1,1,2,3,3,3,4}{1,1,2,3,3,3,4} contains nice numbers 22 and 44.

Vasya wants to split multiset ss into two multisets aa and bb (one of which may be empty) in such a way that the quantity of nice numbers in multiset aa would be the same as the quantity of nice numbers in multiset bb (the quantity of numbers to appear exactly once in multiset aaand the quantity of numbers to appear exactly once in multiset bb).

Input

The first line contains a single integer n (2≤n≤100)n (2≤n≤100).

The second line contains nn integers s1,s2,…sn (1≤si≤100)s1,s2,…sn (1≤si≤100) — the multiset ss.

Output

If there exists no split of ss to satisfy the given requirements, then print “NO” in the first line.

Otherwise print “YES” in the first line.

The second line should contain a string, consisting of nn characters. ii-th character should be equal to ‘A’ if the ii-th element of multiset ssgoes to multiset aa and ‘B’ if if the ii-th element of multiset ss goes to multiset bb. Elements are numbered from 11 to nn in the order they are given in the input.

If there exist multiple solutions, then print any of them.

input

4
3 5 7 1

output

YES
BABA

input

3
3 5 1

output

NO

思路

給你一個集合,現在你要把集合分爲兩個。

定義一個集合中的好數爲:這個集合中出現次數爲1次的數的個數.

現在要求你分出來的這兩個集合中的好數個數一樣(可以爲0).

輸出的時候按照輸入的順序,分成AB兩個集合,在對應位置用AB來標記

首先我們求出題目給出的集合中的出現一次的數的個數sum1和出現次數>2的數的個數sum2.

當sum1爲偶數或者sum2存在就一定可以分。

那麼情況就有:

  1. sum1出現的次數爲奇數且sum2存在
  2. sum1出現的次數爲偶數,sum2隨意

對於情況1,我們可以把sum2中的其中一個數給sum1,這樣就相當於出現一次的數字有偶數個,那麼就可以分了。比如:1 1 1 2我們分爲兩個集合A:1 1 2,B:1,分的時候把出現次數爲3的分給自己對立的集合。

對於情況2,因爲出現次數爲偶數,所以把出現次數爲1的數平均分配給兩個集合即可。

代碼

#include <bits/stdc++.h>
using namespace std;
const int N = 200;
int a[N];
char ans[N];
int main()
{
    int n;
    map<int, int> mp;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        mp[a[i]]++;
    }
    int sum1 = 0, sum2 = 0;
    for (auto num : mp)
    {
        if (num.second == 1)
            sum1++;
        if (num.second > 2)
            sum2++;
    }
    int flag = 0, k = 0;
    if (sum1 % 2 == 0)
        flag = 1;
    else if (sum2)
    {
        flag = 1;
        k = 1;
    }
    puts(flag ? "YES" : "NO");
    int pos = 0;
    if (flag)
    {
        for (int i = 1; i <= n; i++)
        {
            if (mp[a[i]] == 1)
            {
                ans[i] = pos & 1 ? 'A' : 'B';
                pos++;
            }
            else if (mp[a[i]] > 2 && k)
            {
                ans[i] = 'A';
                k = 0;
            }
            else
                ans[i] = 'B';
        }
        for (int i = 1; i <= n; i++)
            putchar(ans[i]);
        puts("");
    }

    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章