UAACO Section 2.2 Party Lamps

灯1和灯7,2和8,3和9...是一样,输出时反复输出前6个的状态.

/*
ID: hysfwjr1
PROG: lamps
LANG: C++
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define _DEBUG 1
#define MAX_L 6
#define MAX_BUTTON 4

#define delim (1<<MAX_L)-1

int buttons[4]={0x3f,0x2a,0x15,0x24};//分别为butoon1、2、3、4
int arry[4];
int isoff=0;//关闭的灯
int ison=0;//开着的灯
int lamp_n;
int result[1<<MAX_L];//存放结果

bool check(int state){//验证状态是否合法,合法则打印
	if((state & ison) != ison)
		return false;
	if((state & isoff) !=0)
		return false;
	return true;
}
void search(int k,int n){
	int i;
	if(k==n){
		int state = delim;
		for(i=0;i<n;++i){
			state ^=  (arry[i] & delim);
		}
		if(check(state)){//验证状态是否合法,合法则打印
			result[state] = 1;
		}
		return;		
	}
	for(i=0;i<MAX_BUTTON;++i){
		arry[k]=buttons[i];
		search(k+1,n);
	}
}
void output(int state){
	for(int i=0;i<lamp_n;++i){		
		int s = (1<<(MAX_L-(i%MAX_L)-1))&state;
		printf("%d",s?1:0);//注意
	}
	printf("\n");
}
int main(){
	int c;//按开关的次数
	int x;
	freopen("lamps.in","r",stdin);
#if _DEBUG==0
	freopen("lamps.out","w",stdout);
#endif
	scanf("%d",&lamp_n);
	scanf("%d",&c);
	while(scanf("%d",&x) && x!=-1){
		int temp=(x-1)%MAX_L;
		ison |= (1<<(MAX_L-temp-1));
	}
	while(scanf("%d",&x) && x!=-1){
		int temp=(x-1)%MAX_L;
		isoff |= (1<<(MAX_L-temp-1));
	}
	if(c <= MAX_BUTTON){//小于4次
		search(0,c);
	}else{
		if(c & 1 ){//c为奇数
			search(0,3);
		}else{
			search(0,4);
		}
	}
	bool flag = false;
	for(int i=0;i<(1<<MAX_L);++i){//输出
		if(result[i]){
			output(i);
			flag = true;
		}
	}
	if(!flag)
		printf("IMPOSSIBLE\n");
	return 0;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值