正在加载...
题干:
Vasya has a multisetssconsisting ofnninteger numbers. Vasya calls some numberxxnice 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 numbers22and44.
Vasya wants to split multisetssinto two multisetsaaandbb(one of which may be empty)in such a way that the quantity of nice numbers in multisetaawould be the same as the quantity of nice numbers in multisetbb(the quantity of numbers to appear exactly once in multisetaaand the quantity of numbers to appear exactly once in multisetbb).
Input
The first line contains a single integern(2≤n≤100)n(2≤n≤100).
The second line containsnnintegerss1,s2,…sn(1≤si≤100)s1,s2,…sn(1≤si≤100)— the multisetss.
Output
If there exists no split ofssto 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 ofnncharacters.ii-th character should be equal to 'A' if theii-th element of multisetssgoes to multisetaaand 'B' if if theii-th element of multisetssgoes to multisetbb.Elements are numbered from11tonnin the order they are given in the input.
If there exist multiple solutions, then print any of them.
Examples
Input
4 3 5 7 1
Output
YES BABA
Input
3 3 5 1
Output
NO
解题报告:
很简单的题意模拟题啊。。。搞WA了好几发、、还是码力不足啊、、写的好复杂、、
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
*/