ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

暑假热身B题

2019-07-22 13:43:49  阅读:298  来源: 互联网

标签:aa perform int 热身 cc 暑假 artists c1


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

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有