比赛 20120612 评测结果 AAAAA
题目名称 灯光 最终得分 100
用户昵称 ZhouHang 运行时间 0.000 s
代码语言 C++ 内存使用 0.00 MiB
提交时间 2012-06-12 18:10:52
显示代码纯文本
/**
*Prob : partya
*Data : 2012-6-12
*Sol  : 容斥+搜索+位运算
*/

#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>

#define MaxANS 10000000

using namespace std;

string ans[MaxANS];
int n,c,num=0;
int way[10];
int now[10];
int final[10];

void turn(int x)
{
	if (x==1)
	  for (int i=1; i<=6; i++)
		now[i]=(now[i]+1)%2;
	if (x==2)
	  for (int i=1; i<=6; i+=2)
		now[i]=(now[i]+1)%2;
	if (x==3)
	  for (int i=2; i<=6; i+=2)
		now[i]=(now[i]+1)%2;
	if (x==4) {
	  now[1]=(now[1]+1)%2;
	  now[4]=(now[4]+1)%2;
	}
}

void doit()
{
	for (int i=1; i<=6; i++)
		now[i]=1;
	for (int i=1; i<=c; i++)
		turn(way[i]);
}

bool check()
{
	for (int i=1; i<=6; i++)
	{
		if (final[i]==2) continue;
		if (final[i]!=now[i]) return false;
	}
	return true;
}

void copy_str()
{
	string s;
	for (int i=1; i<=n; i++)
	{
		int tmp=i%6;
		if (tmp==0) tmp=6;
		s+=now[tmp]+'0';
	}
	for (int i=1; i<=num; i++)
		if (s==ans[i]) return;
	ans[++num]=s;
}

void work(int c)
{
	if (c==0) {
		doit();		
		if ( check() )
			copy_str();
		return;
	}
	
	for (int i=1; i<=4; i++)
	{
		way[c]=i;
		c--;
		work(c);
		c++;
	}
}

int main()
{
	freopen("partya.in","r",stdin);
	freopen("partya.out","w",stdout);
	
	scanf("%d%d",&n,&c);
	
	while (c>4) c-=2;
	
	int tmp;
	for (int i=1; i<=10; i++)
		final[i]=2;
	scanf("%d",&tmp);
	while (tmp!=-1)
	{
		tmp%=6;
		if (tmp==0) tmp=6;
		final[tmp]=1;
		scanf("%d",&tmp);
	}
	scanf("%d",&tmp);
	while (tmp!=-1)
	{
		tmp%=6;
		if (tmp==0) tmp=6;
		final[tmp]=0;
		scanf("%d",&tmp);
	}

	work(c);
	
	sort(ans+1,ans+1+num);
	
	for (int i=1; i<=num; i++)
	{
		cout<<ans[i];
		cout<<endl;
	}
	
	fclose(stdin); fclose(stdout);
	return 0;
}