Vasya and Multisets

题意:
在一个集合中只出现一次的数是nice的。给出一个集合,我们能否将其分为两个集合,每个集合的nice数的数量一样多。

思路:
因为每个数都是小于等于100的,所以我们开个数组b将每个数出现的次数记录下来。还要记录出现次数为1和大于等于三的数量。因为等于1的,肯定是nice,那我们一定得将它们分开在两个集合中。如果等于1的数量是偶数,我们只要将前一半的1的数分到一组,其余的数分到另一组就可以了。如果是奇数的话,我们就应该将大于等于3的数分一个给到第一个数组,剩下的留在B数组。因为大于等于3的,分给A一个作为nice数,他剩下的一定大于等于2,所以留在B数组中不作为nice数。输出的结果如果划在A中输出A,否则输出B。

代码:


#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
using namespace std;
const int MAX = 2e5 + 10;
const int inf = 0x3f3f3f3f;
int a[MAX],b[MAX];
int main()
{
	int n;
	cin >> n;
	for(int i = 1 ; i <= n ; i++)
	{
		cin >> a[i];
		b[a[i]]++;
	}
	int s0 = 0 , num = 0;
	for(int i = 1 ; i <= 100 ; i++)
	{
		if(b[i]==1)
		  s0++;//只出现一次的个数 
		if(b[i]>=3)
		  num++;//出现次数大于等于三的个数 
	}
	if(s0%2==1&&num==0)
	{
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	if(s0%2==0)
	{
		s0/=2;
		for(int i = 1 ; i <= n ; i++)
		{
			if(b[a[i]]==1&&s0)
			{
				--s0;
				printf("A");
			}
			else
			   printf("B");
		}
	}
	else
	{
		bool flag = 0;
		s0/=2;
		for(int i = 1 ; i <= n ; i++)
		{
			if(b[a[i]]==1)
			{
				if(s0)
				{
					--s0;
					printf("A");
				}
				else
				  printf("B");
			}
			else if(b[a[i]]>=3)
			{
				if(flag==0)
				{
					flag = 1;
					cout << "A";
				}
				else
				  printf("B");
			}
			else
			  printf("B");
		}
	}
	return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值