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 ;
}

最新文章

  1. Atitti 知识图谱构建方法attilax 总结
  2. CSS 概念 Block Inline Containing block
  3. HOWTO - 压缩封装的Setup.exe(纯MSI)安装包获取运行Log
  4. Asp.net Core WebApi 支持json/xml格式的数据返回
  5. WCF学习之二
  6. Linux下Web服务器环境搭建LNMP一键安装包[20130911更新]
  7. C++ 继承的访问权限
  8. 【转】shell 教程——02 几种常见的Shell
  9. ios开发-第二天
  10. cookie, session, token 是什么 以及相应的安全考量
  11. beta 答辩总结
  12. mongoose 基础api 图表整理
  13. Central Control Over Distributed Routing阅读笔记
  14. Docker(二)-Docker安装
  15. JAVA各种系统架构图及其简介
  16. 【总结】java regex 正则表达式 提取数字和去除数字,过滤数字,提取价格
  17. Android之旅-Intent与Intent Filter[上]
  18. CentOS6.5下Cloudera安装搭建部署大数据集群(图文分五大步详解)(博主强烈推荐)
  19. python下使用tesserocr遇到的一些坑
  20. TensorFlow GPU 的使用

热门文章

  1. 开源定时任务框架Quartz(一)
  2. Java中数据存储分配
  3. 【转】利用匿名namespace解决C++中重复定义的问题
  4. SAS学习笔记28 非参数秩和检验
  5. CAS 5.x搭建常见问题系列(3).Failure to find org.apereo.cas:cas-server-support-pm-jdbc:jar:5.1.9
  6. .NET Core 使用ModelBinder去掉所有参数的空格
  7. 转录组测序(RNA-seq)技术
  8. 傅里叶变换通俗解释及快速傅里叶变换的python实现
  9. adminMongo:mongoDB node GUI(mongoDB图形化界面)
  10. ubantu18.04 配置nginx与uwsgi(前后端分离)