暑假热身B题

CodeForces 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");	
}
MATLAB主动噪声和振动控制算法——对较大的次级路径变化具有鲁棒性内容概要:本文主要介绍了一种在MATLAB环境下实现的主动噪声和振动控制算法,该算法针对较大的次级路径变化具有较强的鲁棒性。文中详细阐述了算法的设计原理与实现方法,重点解决了传统控制系统中因次级路径动态变化导致性能下降的问。通过引入自适应机制和鲁棒控制策略,提升了系统在复杂环境下的稳定性和控制精度,适用于需要高精度噪声与振动抑制的实际工程场景。此外,文档还列举了多个MATLAB仿真实例及相关科研技术服务内容,涵盖信号处理、智能优化、机器学习等多个交叉领域。; 适合人群:具备一定MATLAB编程基础和控制系统理论知识的科研人员及工程技术人员,尤其适合从事噪声与振动控制、信号处理、自动化等相关领域的研究生和工程师。; 使用场景及目标:①应用于汽车、航空航天、精密仪器等对噪声和振动敏感的工业领域;②用于提升现有主动控制系统对参数变化的适应能力;③为相关科研项目提供算法验证与仿真平台支持; 阅读建议:建议读者结合提供的MATLAB代码进行仿真实验,深入理解算法在不同次级路径条件下的响应特性,并可通过调整控制参数进一步探究其鲁棒性边界。同时可参考文档中列出的相关技术案例拓展应用场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值