暑假热身B题

http://codeforces.com/problemset/problem/1138/B
Polycarp is a head of a circus troupe. There are n — an even number — artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then ci=1, otherwise ci=0), and whether they can perform as an acrobat (if yes, then ai=1, otherwise ai=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 n2),
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 n (2≤n≤5000, n is even) — the number of artists in the troupe.

The second line contains n digits c1c2…cn, the i-th of which is equal to 1 if the i-th artist can perform as a clown, and 0 otherwise.

The third line contains n digits a1a2…an, the i-th of which is equal to 1, if the i-th artist can perform as an acrobat, and 0 otherwise.

Output
Print n2 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.

Examples
Input
4
0011
0101
Output
1 4
Input
6
000000
111111
Output
-1
Input
4
0011
1100
Output
4 3
Input
8
00100101
01111100
Output
1 2 3 6
C中等于1的可当小丑,a中可当演员;
有两场表演,分别有n/2个人,一人只能参加一场;
第一场中能当小丑的人数等于第二场中能当演员的。
一开始没想到是暴力枚举。。。
设四种人01为a,10b,11c,00d;
参加第一场的人数分别为a1,b1,c1,d1;
从题意中知道a1+b1+c1+d1=n/2,
d1=n/2+c1-a-c;
从而枚举d1,b1得到答案;

#include<stdio.h>
char aa[5005],cc[5005];
int n;
int an1,an2,an3,an4;
int main()
{
	int a=0,b=0,c=0,d=0;
	int a1,b1,c1,d1;
	scanf("%d",&n);
	scanf("%s",cc+1);
	scanf("%s",aa+1);
	for(int i=1;i<=n;i++)
	{
	    if(cc[i]=='0'&&aa[i]=='0')
	    d++;
	    else if(cc[i]=='0'&&aa[i]=='1')
	    a++;
	    else if(cc[i]=='1'&&aa[i]=='1')
	    c++;
	    else if(cc[i]=='1'&&aa[i]=='0')
	    b++;
	}
	int flag=0;
	for(a1=0;a1<=a;a1++)
	{
		
	    for(c1=0;c1<=c;c1++)
	    {
		    d1=n/2+c1-a-c;
		    b1=n/2-a1-c1-d1;
		    if(d1<=d&&d1>=0&&b1<=b&&b1>=0)
		    {
			    flag=1;
			    break;
		    }
	    }
		if(flag)
		break;	
	}
	if(!flag)
	printf("-1\n");
	else
	{
		int cout=0;
	    for(int i=1;i<=n;i++)
		{
		    if(cout==a1)
			break;
			if(cc[i]=='0'&&aa[i]=='1')
			{
				printf("%d ",i);
			    cout++;
			}			
			
		}
		cout=0;	
		for(int i=1;i<=n;i++)
		{
		    if(cout==c1)
			break;
			if(cc[i]=='1'&&aa[i]=='1')
			{
				printf("%d ",i);
			    cout++;
			}			
			
		}
		cout=0;	
		for(int i=1;i<=n;i++)
		{
		    if(cout==b1)
			break;
			if(cc[i]=='1'&&aa[i]=='0')
			{
				printf("%d ",i);
			    cout++;
			}			
			
		}
		cout=0;	
		for(int i=1;i<=n;i++)
		{
		    if(cout==d1)
			break;
			if(cc[i]=='0'&&aa[i]=='0')
			{
				printf("%d ",i);
			    cout++;
			}			
			
		}
	}
	printf("\n");	
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值