传送门

[http://codeforces.com/contest/1051/problem/C]

题意

给你一堆数,问是否可以分为两堆使得两堆里只出现一下的数字的种类相等,可以输出任意一种分的方式

分析

具体看代码

代码

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//freopen("in.txt","r",stdin);
int n,i;
int a[110],b[110];
while(cin>>n){
memset(b,0,sizeof(b));
for(i=0;i<n;i++){
cin>>a[i];
b[a[i]]++;//统计每个数字的个数
}
int cnt=0;
bool f=false,t=false;
for(i=1;i<=100;i++){
if(b[i]==1)
cnt++;//统计个数为1的种类数
if(b[i]>2) f=true;//看有没有个数大于2的
}
int h=1; if(cnt%2==0)//如果个数为1的数字种类为偶数肯定可以分为两个集合均即可
{//剩下的大于等于2的随便扔进那一堆
cout<<"YES\n";
for(i=0;i<n;i++){
if(b[a[i]]>1) cout<<'A';
else if(b[a[i]]==1&&h==1){
cout<<'A';
h*=-1;
}
else if(b[a[i]]==1&&h==-1){
cout<<'B';
h*=-1;
}
}
cout<<endl;
} else if(cnt%2==1&&f){//只有个数为1的数字种类为奇数且有个数大于2的才可以均分
cout<<"YES\n";//具体操作把一个大于2的一个拿来凑使得个数为1的数字种类为偶数,剩下的大于等于2的随便扔进那一堆
for(i=0;i<n;i++){
if(b[a[i]]==2) cout<<'A'; else if(b[a[i]]>2&&t){
cout<<'A';
}
else if(b[a[i]]>2&&!t){
cout<<'B';
t=true;
}
else if(b[a[i]]==1&&h==1){
cout<<'A';
h*=-1;
}
else if(b[a[i]]==1&&h==-1){
cout<<'B';
h*=-1;
}
}
cout<<endl;
}
else cout<<"NO\n";//剩下皆不可以均分为俩个集合
}
return 0;
}

C. Vasya and Multisets的更多相关文章

  1. Vasya and Multisets CodeForces - 1051C(英语限制了我的想象力)

    题意: 对输入的每个数都进行分配到两个多重集中,问分配完以后 每个多重集中的个数为1的元素是否相等  相等则输出一个分配方式, 不想等为NO 解析: 三种情况 1.原数列中个数为1 的数的个数为偶数 ...

  2. 2018.9.20 Educational Codeforces Round 51

    蒟蒻就切了四道水题,然后EF看着可写然而并不会,中间还WA了一次,我太菜了.jpg =.= A.Vasya And Password 一开始看着有点虚没敢立刻写,后来写完第二题发现可以暴力讨论,因为保 ...

  3. Educational Codeforces Round 51 (Rated for Div. 2)

    做了四个题.. A. Vasya And Password 直接特判即可,,为啥泥萌都说难写,,,, 这个子串实际上是忽悠人的,因为每次改一个字符就可以 我靠我居然被hack了???? %……& ...

  4. CodeForces Educational Codeforces Round 51 (Rated for Div. 2)

    A:Vasya And Password 代码: #include<bits/stdc++.h> using namespace std; #define Fopen freopen(&q ...

  5. Codeforces Edu Round 51 A-D

    A. Vasya And Password 模拟题,将所缺的种类依次填入"出现次数$ >1 $"的位置,替换掉Ta即可. #include <iostream> ...

  6. Milliard Vasya's Function-Ural1353动态规划

    Time limit: 1.0 second Memory limit: 64 MB Vasya is the beginning mathematician. He decided to make ...

  7. CF460 A. Vasya and Socks

    A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. 递推DP URAL 1353 Milliard Vasya's Function

    题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k] ...

  9. Codeforces Round #281 (Div. 2) D. Vasya and Chess 水

    D. Vasya and Chess time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. Python进阶(二)

    高阶函数 1.把函数作为参数传入,这样的函数称为高阶函数,函数式编程就是指这种高度抽象的编程范式. 2.Python内建了map( )和reduce( ) 函数 map()函数接收两个参数,一个是函数 ...

  2. 【ReactNative】Mac下分分钟打包 Android apk

    时间:2016-11-20 09:17:07 地址:https://github.com/zhongxia245/blog/issues/52 Mac 下 ReactNative如何打包构建Andro ...

  3. 装饰者模式vs适配器模式

    http://www.cnblogs.com/tekkaman/p/3275077.html 1.关于新职责:适配器也可以在转换时增加新的职责,但主要目的不在此.装饰者模式主要是给被装饰者增加新职责的 ...

  4. idea报错:[2016-08-31 09:20:10,763] Artifact xxx:war exploded: Error during artifact deployment.

    [2016-08-31 09:20:10,763] Artifact newClassProject1:war exploded: Error during artifact deployment. ...

  5. ECS简述

    一.查看ECS实例 使用场景 •实例的日常维护 •实例运行状态和详细信息的查看 二.启动ECS实例 使用场景 •实例停止运行之后的再次启动 三.停止.重启ECS实例 使用场景 •实例运行的服务暂停时停 ...

  6. 各个版本的 Oracle 11.2.0.4下载地址

    Oracle 11.2.0.4下载地址 Linux x86: https://updates.oracle.com/Orion/Services/download/p13390677_112040_L ...

  7. PAT A1034 Head of a Gang (30 分)——图遍历DFS,字符串和数字的对应保存

    One way that the police finds the head of a gang is to check people's phone calls. If there is a pho ...

  8. C++ assert断言

    assert断言通常用于调试,用法如下: assert(expr); // 当expr==0时,系统会调用abort来终止程序运行 调试完成后,可以在include <assert.h>之 ...

  9. Android学习之键盘事件

    java代码: package com.example.keyboardtest; import android.app.Activity; import android.os.Bundle; imp ...

  10. Python 远程桌面协议RDPY简介

    转载请注明:@小五义http://www.cnblogs.com/xiaowuyiQQ群:64770604 RDPY 是基于 Twisted Python 实现的微软 RDP 远程桌面协议. RDPY ...