• 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 b(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 aa and the quantity of numbers to appear exactly once in multiset bb).

    Input

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

    The second line contains nn integers s1,s2,sn (1si100)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 ss goes 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.

    Examples
    input
    Copy
    4
    3 5 7 1
    output
    Copy
    YES
    BABA
    input
    Copy
    3
    3 5 1
    output
    Copy
    NO

    写的垃圾,疯狂扣细节
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <unordered_set>
    #include <unordered_map>
    //#include <xfunctional>
    #define ll long long
    #define mod 1000000007
    using namespace std;
    int dir[4][2] = { { 0,1 },{ 0,-1 },{ -1,0 },{ 1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    
    int main()
    {
        int n, cnt = 0,pos=0;
        cin >> n;
        vector<int> s(101,0),a(n+1);
        for (int i = 1; i <= n; i++)
        {
            int t;
            cin >> t;
            a[i] = t;
            s[t]++;
            if (s[t] > 2)
            {
                pos = t;
            }
        }
        for (int i = 1; i <= 100; i++)
        {
            if (s[i] == 1)
                cnt++;
        }
        if (cnt % 2 == 0)
        {
            cout << "YES" << endl;
            int flag = 1;
            for (int i = 1; i <= n; i++)
            {
                if (flag && s[a[i]]==1)
                {
                    cout << "A";
                    flag = 0;
                }
                else if (flag==0 && s[a[i]] == 1)
                {
                    cout << "B";
                    flag = 1;
                }
                else if(s[a[i]]>1)
                {
                    cout << "B";
                }
            }
        }
        else if (cnt % 2 && pos)
        {
            int flag = 1,firstone=1,special=1;
            cout << "YES" << endl;
            for (int i = 1; i <= n; i++)
            {
                if (a[i] == pos)
                {
                    if (special)
                    {
                        cout << "A";
                        special = 0;
                    }
                    else
                    {
                        cout << "B";
                    }
                    continue;
                }
                if (s[a[i]] == 1)
                {
                    if (firstone)
                    {
                        cout << "B";
                        firstone = 0;
                        continue;
                    }
                    if (flag && s[a[i]] == 1)
                    {
                        cout << "A";
                        flag = 0;
                    }
                    else if (flag == 0 && s[a[i]] == 1)
                    {
                        cout << "B";
                        flag = 1;
                    }
                }    
                else if(s[a[i]]>1)
                {
                        cout << "B";
                }
            }
        }
        else
            cout << "NO";
        return 0;
    }
  • 相关阅读:
    双击bat用CMD窗口打开jar (专为没有界面的java程序设计的) 拂晓风起
    CString 在_UNICODE宏定义下和普通ASCII编码下的不同 拂晓风起
    java web部署 启动线程 (监听socket等) 拂晓风起
    火狐下不错的插件
    JQuery插件,weebox,可移动层,替换模态框
    一些功能不错的开源工具(DNSPod、MailServer、Bug跟踪系统、VS代码检查、VS反翻译)
    用cwRsync同步文件
    DreamWeaver、EditPlus查找两个字符之间字符串的正则表达式
    oarcle hql语句中的 (xx=:名称)hql语句中传值
    this man
  • 原文地址:https://www.cnblogs.com/dealer/p/12439117.html
Copyright © 2020-2023  润新知