其他分享
首页 > 其他分享> > 暑假热身B题

暑假热身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");	

}

标签:aa,perform,int,热身,cc,暑假,artists,c1
来源: https://blog.csdn.net/evilwind2000/article/details/96850371