https://codeforc.es/contest/1138/problem/B

B. Circus
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp is a head of a circus troupe. There are nn — an even number — artists in the troupe. It is known whether the ii-th artist can perform as a clown (if yes, then ci=1ci=1, otherwise ci=0ci=0), and whether they can perform as an acrobat (if yes, then ai=1ai=1, otherwise ai=0ai=0).

Split the artists into two performances in such a way that:

  • each artist plays in exactly one performance,
  • the number of artists in the two performances is equal (i.e. equal to n2n2),
  • the number of artists that can perform as clowns in the first performance is the same as the number of artists that can perform as acrobats in the second performance.
Input

The first line contains a single integer nn (2≤n≤50002≤n≤5000, nn is even) — the number of artists in the troupe.

The second line contains nn digits c1c2…cnc1c2…cn, the ii-th of which is equal to 11 if the ii-th artist can perform as a clown, and 00 otherwise.

The third line contains nn digits a1a2…ana1a2…an, the ii-th of which is equal to 11, if the ii-th artist can perform as an acrobat, and 00 otherwise.

Output

Print n2n2 distinct integers — the indices of the artists that should play in the first performance.

If there are multiple answers, print any.

If there is no solution, print a single integer −1−1.

Examples
input

Copy
4
0011
0101
output

Copy
1 4
input

Copy
6
000000
111111
output

Copy
-1
input

Copy
4
0011
1100
output

Copy
4 3
input

Copy
8
00100101
01111100
output

Copy
1 2 3 6
Note

In the first example, one of the possible divisions into two performances is as follows: in the first performance artists 11 and 44 should take part. Then the number of artists in the first performance who can perform as clowns is equal to 11. And the number of artists in the second performance who can perform as acrobats is 11 as well.

In the second example, the division is not possible.

In the third example, one of the possible divisions is as follows: in the first performance artists 33 and 44 should take part. Then in the first performance there are 22 artists who can perform as clowns. And the number of artists in the second performance who can perform as acrobats is 22 as well.

题意:有四种类型的人,(01)  (10)  (00)  (11),求一种分配方案,使两队人数相同,并且A队第一位为1的个数与B队第二位为1的个数相同 (n<=5000)

题解:直接枚举A队(10)和(01)的人数为 i , j ,设A队(11)为x,则可以得到一个等式 i+x = (n4-x) + (n1-j),即 x=(n4+n1-j-i)/2,所以可以解出相应的A队(11)的个数x以及(00)的个数 n/2-x-i-j

 #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
#define debug(x) cout<<"["<<#x<<"]"<<" is "<<x<<endl;
typedef long long ll;
char ch[],ch2[];
int bq[];
int main(){
int n;
scanf("%d",&n);
scanf("%s",ch+);
scanf("%s",ch2+);
int a,b,c,d;
a=b=c=d=;
for(int i=;i<=n;i++){
if(ch[i]==''&&ch2[i]=='')a++;
else if(ch[i]==''&&ch2[i]=='')b++;
else if(ch[i]==''&&ch2[i]=='')c++;
else if(ch[i]==''&&ch2[i]=='')d++;
}
int a1,a2,a3,a4;
a1=a2=-;
for(int i=;i<=b;i++){
int f=;
for(int j=;j<=c;j++){
int x=i;
int y=c-j;
a3=(a+y-x)/;
a4=n/-x-j-a3;
if((a+y-x)%==&&a3>=&&a3<=a&&a4>=&&a4<=d){
a1=i;
a2=j;
f=;
break;
}
}
if(f)break;
}
if(a1==-&&a2==-){
printf("-1\n");
}
else{
int tot=;
for(int i=;i<=n;i++){
if(ch[i]==''&&ch2[i]==''&&a3){
a3--;
bq[++tot]=i;
}
else if(ch[i]==''&&ch2[i]==''&&a1){
a1--;
bq[++tot]=i;
}
else if(ch[i]==''&&ch2[i]==''&&a2){
a2--;
bq[++tot]=i;
}
else if(ch[i]==''&&ch2[i]==''&&a4){
a4--;
bq[++tot]=i;
}
}
for(int i=;i<=n/;i++){
printf("%d",bq[i]);
char cc=(i==n/)?'\n':' ';
printf("%c",cc);
}
}
return ;
}

[cf1138BCircus][枚举,列等式]的更多相关文章

  1. [hdu5255]枚举

    思路:这题与csu1392题目类似,方法类似.枚举最高位,最低位和中间数字的长度,然后列等式,计算中间的数字,看长度是不是跟枚举的一致,需要注意的是中间数字可以有前导0,如果根据等式算出来的中间数字为 ...

  2. [WinForm] DataGridView 绑定 DT && ComboBox 列绑定 Dict

    一  需求介绍 一般像枚举类型的数据,我们在数据库里存储着诸如(1.2.3.4-)或者("001"."002"."003"-)此类,但是界面 ...

  3. hibernate 使用枚举字段的最佳实践

    枚举类虽然很简单,但是却往往是系统中业务逻辑最集中最复杂的地方.本文将会分享我们项目中基于hibernate的枚举类使用规范,包含数据库中枚举列数据类型.注释.枚举列与枚举类的映射等. 一.枚举类定义 ...

  4. Gym 101308D Database 枚举

    大致题意: 给出一张表,n行m列,每一行的列用逗号分隔.判断这个表是否有冗余元素.如果一张表中有两行两列对应的的元素相同,那么这个表就有冗余元素. 分析: 先枚举要排序的列,然后枚举行,如果相邻两行相 ...

  5. SP1026 FAVDICE - Favorite Dice 数学期望

    题目描述: 一个n面的骰子,求期望掷几次能使得每一面都被掷到. 题解:先谈一下期望DP. 一般地,如果终止状态固定,我们都会选择逆序计算. 很多题目如果顺序计算会出现有分母为 0 的情况,而逆序计算中 ...

  6. ACM模板(持续补完)

    1.KMP #include<cstring> #include<algorithm> #include<cstdio> using namespace std; ...

  7. bzoj1720: [Usaco2006 Jan]Corral the Cows 奶牛围栏

    金组题什么的都要绕个弯才能AC..不想银组套模板= = 题目大意:给n个点,求最小边长使得此正方形内的点数不少于c个 首先一看题就知道要二分边长len 本来打算用二维前缀和来判断,显然时间会爆,而且坐 ...

  8. Ural-1146Maximum Sum-最大子矩阵

    Time limit: 0.5 second Memory limit: 64 MB Given a 2-dimensional array of positive and negative inte ...

  9. haligong2016

    A 采用递推的方法,由于要到达棋盘上的一个点,只能从左边或者上边过来,根据加法原则,到达某一点的路径数目,就等于到达其相邻的上点和左点的路径数目的总和.所有海盗能达到的点将其路径数置为0即可. #in ...

随机推荐

  1. Hadoop学习(6)-HBASE的安装和命令行操作和java操作

    使用HABSE之前,要先安装一个zookeeper 我以前写的有https://www.cnblogs.com/wpbing/p/11309761.html 先简单介绍一下HBASE HBASE是一个 ...

  2. C++:标准模板库map

    一:介绍 map是STL的关联式容器,以key-value的形式存储,以红黑树(平衡二叉查找树)作为底层数据结构,对数据有自动排序的功能. 命名空间为std,所属头文件<map> 注意:不 ...

  3. PAT甲级 模拟题_C++题解

    模拟题 PAT (Advanced Level) Practice 模拟题 目录 1008 Elevator (20) 1042 Shuffling Machine (20) 1046 Shortes ...

  4. pythn print格式化输出:%s与%d

    pythn print格式化输出. %r 用来做 debug 比较好,因为它会显示变量的原始数据(raw data),而其它的符号则是用来向用户显示输出的. 1. 打印字符串 print (" ...

  5. MySQL explain功能展示的各种信息的解释

    1.id: MySQL Query Optimizer 选定的执行计划中查询的序列号. 2.select_type: 所使用的查询类型,主要有以下这几种查询类型.  DEPENDENT SUBQUER ...

  6. 使用Duilib开发Windows软件(2)——控件的基本介绍

    XML 先学习xml https://www.w3cschool.cn/xml/xml-xml-tutorialhc4o1t5m.html 控件 上图是我们下载的NIM_Duilib_Framewor ...

  7. NeurIPS 2018 中的贝叶斯研究

    NeurIPS 2018 中的贝叶斯研究 WBLUE 2018年12月21日   雷锋网 AI 科技评论按:神经信息处理系统大会(NeurIPS)是人工智能领域最知名的学术会议之一,NeurIPS 2 ...

  8. vim编辑器中的替换(转)

    转1:https://www.cnblogs.com/david-wei0810/p/6385988.html 转2:https://blog.csdn.net/doubleface999/artic ...

  9. hdu 2089 入手数位dp问题

    数位dp解决的问题是指求在一段数的区间里面 满足条件的数的个数 核心为两点 http://wenku.baidu.com/link?url=tpfIYzhx_MzevpIM58UZ66pr-87MCF ...

  10. (一)Centos之VMware虚拟机安装

    一.下载 64位的VM12 安装包: http://pan.baidu.com/s/1bpzoXQZ 二.安装 点击下一步: 老规矩,打勾,下一步: 这里我们新建一个文件夹 VM12 最好放在D盘或者 ...