【CodeForces - 1051C 】Vasya and Multisets (模拟)
題干:
Vasya has a multiset?ss?consisting of?nn?integer numbers. Vasya calls some number?xxnice 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?aa?and 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?ss?goes to multiset?aa?and 'B' if if the?ii-th element of multiset?ss?goes to multiset?bb.?Elements are numbered from?11to?nn?in the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4 3 5 7 1Output
YES BABAInput
3 3 5 1Output
NO解題報告:
? ?很簡單的題意模擬題啊。。。搞WA了好幾發(fā)、、還是碼力不足啊、、寫的好復(fù)雜、、
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; int bk[1005],qq[1005]; char opa[1005]; int a[1005],cnt; int main() {int n;cin>>n;for(int i = 1; i<=n; i++) {scanf("%d",a+i);bk[a[i]]++;}bool flag = 0;for(int i = 1; i<=n; i++) {if(bk[a[i]] == 2) opa[i]='A';else if(bk[a[i]] == 1) {cnt++;if(flag) opa[i]='A';else opa[i]='B';flag=!flag;}}if(cnt % 2 == 0) {puts("YES");for(int i = 1; i<=n; i++) {if(opa[i] !=0) putchar(opa[i]);else putchar('A');}return 0 ;}bool ok=0;for(int i = 1; i<=n; i++) {if(opa[i] == 0) {if(bk[a[i]] > 2) {if(flag) {opa[i] = 'A';for(int j = i+1; j<=n; j++) {if(a[j] == a[i]) opa[j] = 'B';}}else {opa[i] = 'B';for(int j = i+1; j<=n; j++) {if(a[j] == a[i]) opa[j] = 'A';}}ok=1;break;}}}if(ok==0) {puts("NO");return 0 ;}puts("YES");for(int i = 1; i<=n; i++) {if(opa[i]!=0) putchar(opa[i]);else putchar('A');}return 0 ;} /* 12 1 2 3 4 5 5 6 6 6 7 9 11 YES ABABAABAAABA 7 1 2 3 4 4 4 4 YES ABABAAA */?
總結(jié)
以上是生活随笔為你收集整理的【CodeForces - 1051C 】Vasya and Multisets (模拟)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: silent.exe - silent是
- 下一篇: 【CodeForces - 764B 】