CodeForces 353B Two Heaps
Valera has 2·n cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses n cubes and puts them in the first heap. The remaining cubes form the second heap.
Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer — the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap.
Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible?
The first line contains integer n (1 ≤ n ≤ 100). The second line contains 2·n space-separated integers ai (10 ≤ ai ≤ 99), denoting the numbers on the cubes.
In the first line print a single number — the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2·n numbers bi (1 ≤ bi ≤ 2). The numbers mean: the i-th cube belongs to the bi-th heap in your division.
If there are multiple optimal ways to split the cubes into the heaps, print any of them.
1
10 99
1
2 1
2
13 24 13 45
4
1 2 2 1
In the first test case Valera can put the first cube in the first heap, and second cube — in second heap. In this case he obtain number1099. If he put the second cube in the first heap, and the first cube in the second heap, then he can obtain number 9910. In both cases the maximum number of distinct integers is equal to one.
In the second test case Valera can obtain numbers 1313, 1345, 2413, 2445. Note, that if he put the first and the third cubes in the first heap, he can obtain only two numbers 1324 and 1345.
重复出现2次及以上的数,先在两边各分一个。。。只出现一次的数分成尽量相等的两半。。。。
用剩下的出现2次及以上的数把两个堆补齐。。。。。
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n,use[],a[],cnt[],cnt1=,cnt2=,temp=,sol[],size1=; int main()
{
scanf("%d",&n);
n=n*;
for(int i=;i<n;i++)
{
scanf("%d",a+i);
cnt[a[i]]++;
}
for(int i=;i<=;i++)
{
if(cnt[i]>=) cnt2++;
else if(cnt[i]==) cnt1++;
}
int ans=(cnt2+(cnt1/))*(cnt2+((cnt1+)/));
for(int i=;i<n;i++)
{
if(cnt[a[i]]>=&&use[a[i]]<)
{
sol[i]=++use[a[i]];
if(sol[i]==) size1++;
}
else if(cnt[a[i]]==)
{
if(temp<cnt1/)
{
sol[i]=;
size1++;
temp++;
}
else sol[i]=;
}
}
printf("%d\n",ans);
for(int i=;i<n;i++)
{
if(sol[i]) printf("%d ",sol[i]);
else
{
if(size1<n/) {printf("1 "); size1++;}
else printf("2 ");
}
}
return ;
}
CodeForces 353B Two Heaps的更多相关文章
- Codeforces 538 F. A Heap of Heaps
\(>Codeforces \space 538 F. A Heap of Heaps<\) 题目大意 :给出 \(n\) 个点,编号为 \(1 - n\) ,每个点有点权,将这些点构建成 ...
- L - A Heap of Heaps CodeForces - 538F 主席树
L - A Heap of Heaps CodeForces - 538F 这个是一个还比较裸的静态主席树. 这个题目的意思是把这个数组变成k叉树,然后问构成的树的子树小于等于它的父节点的对数有多少. ...
- Codeforces Round #300 F - A Heap of Heaps (树状数组 OR 差分)
F. A Heap of Heaps time limit per test 3 seconds memory limit per test 512 megabytes input standard ...
- Codeforces 955F Heaps - 动态规划
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一棵以1为根的树,定义$dp_{k}(u)$表示在$u$的子树内存在的深度最大的满k叉树的深度,求$\sum_{u = 1}^{n}\su ...
- Codeforces Round #471 (Div. 2) F. Heaps(dp)
题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\ ...
- CodeForces 538F A Heap of Heaps
题意 给定一个长度为n的数组A,将它变为一颗k叉树(1 <= k <= n - 1)(堆的形式编号). 问对于每一个k,有多少个节点小于它的父节点. 解题 显然,最初的想法是暴力.因为树的 ...
- Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集 bfs
F. Polycarp and Hay 题目连接: http://www.codeforces.com/contest/659/problem/F Description The farmer Pol ...
- Codeforces Round #300 解题报告
呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- 浅析基本AI五子棋算法
五子棋是所有棋类博弈中比较简单的了,这里介绍的也只是一种非常基本的AI策略.其实,包括之前的AI贪吃蛇,感觉这两个AI其实体现的都是一种建模思想,把一个现实中的问题模型化,抽象化,得到其一般特征,再设 ...
- HDU 4223 Dynamic Programming?(最小连续子序列和的绝对值O(NlogN))
传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solvi ...
- 申请https证书需要注意的4大问题
HTTPS证书是什么 https证书是数字证书中的一种,由受信任的数字证书颁发机构CA如[沃通CA]在验证服务器身份后颁发,具有服务器身份验证和数据传输加密 功能,因其要配置在服务器上,所以也称SSL ...
- sql 查询每月的销售金额
sql 数据分月统计,表中只有每天的数据,现在要求求一年中每个月的统计数据(一条sql) SELECT MONTH ( 那个日期的字段 ), SUM( 需要统计的字段, 比如销售额什么的 ...
- sed,grep,awk命令常用法
查看当天nginx访问日志中2016:03:25到2016:05点passport.mingxiao.com域名访问量最多的url,可以查看网站是否被刷. 法一: sed -n '/2016:03:2 ...
- tomcat十大安全优化措施
1.telnet管理端口保护 使用telnet连接进来可以输入SHUTDOWN可以直接关闭tomcat,极不安全,必须关闭.可以修改默认的管理端口8005改为其他端口,修改SHUTDOWN指令为其他字 ...
- C#实现录制屏幕
以前写过两篇录制麦克风语音和摄像头视频的文章(实现语音视频录制.在服务器端录制语音视频),最近有朋友问,如果要实现屏幕录制这样的功能,该怎么做了?实际上原理是差不多的,如果了解了我前面两篇文章中介绍的 ...
- HTTP 传输内容的压缩
一.HTTP压缩和内容编码的区别 HTTP压缩,在HTTP协议中,其实是内容编码的一种. 在http协议中,可以对内容(也就是body部分)进行编码, 可以采用gzip这样的编码. 从而达到压缩的目的 ...
- thinkphp安装 版本 3.1.3
基础版: 只有thinkphp基础运行功能 完整版:基础运行能力,还有图片.上传等各种处理类(建议下载完整版) 重要的三个变量 define('APP_DEBUG',True); // 定义应用目录d ...
- Realm简单使用小记
一.项目环境:纯OC 载入Realm: pod 'Realm' 二.为了方便调用可以写一个Realm类的分类 #import <Foundation/Foundation.h> #impo ...