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.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
随机推荐
- iOS WebView调用JS的一个小坑
假如调用一个函数,传入的参数为String,要以这样的格式传入: let resultStr="1234" self.webView.stringByEvaluatingJavaS ...
- Swift 吐槽下Swift里一个逼死强迫症的语法:中缀语法
中缀语法是OC里特有的一种,就是在函数的参数前面加一个解释词,让调用的时候明白该参数的含义 比如: -(void)processDataWithparamaA:(NSString *)paramaA ...
- 加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: FINAL
Stat2.3x Inference(统计推断)课程由加州大学伯克利分校(University of California, Berkeley)于2014年在edX平台讲授. PDF笔记下载(Acad ...
- 数据结构与算法分析 - 最大公约数(gcd & extended_gcd)
以下内容均节选自<算法导论>第31章 最大公约数 定义:若:\[\begin{array}{l}a = p_1^{e_1}p_2^{e_2} \ldots p_r^{e_r}\\b = p ...
- JQuery 技巧积累与总结
1.获得select 元素选中的值 $('#WishlistSelect option:selected').val(); 2.设置按钮的disabled属性的实现代码 $('#button').at ...
- Bitmap四种属性
http://blog.csdn.net/rabbit_in_android/article/details/49967461 Bitmap: (1) public Bitmap (int w ...
- BZOJ4668: 冷战
并查集,按秩合并,树高log,暴力查询. 果然bzoj新挂的题中过的人多的全是sb题. 写了一发秒WA,发现姿势不对.(@_@) 然后过了50min,开始怀疑人生.(*_*) 这么长时间我lct都写完 ...
- Python字典和集合
Python字典操作与遍历: 1.http://www.cnblogs.com/rubylouvre/archive/2011/06/19/2084739.html 2.http://5iqiong. ...
- JQuery------prevAll(),nextAll(),attr()方法的使用
$(this).nextAll(".Rec").find("input").attr("checked", false); $(this). ...
- WinForm------TextEdit控件内容字体变*号
"属性" -> “Properties” -> “LookAndFeel” -> “PasswordChar”