UAACO Section 2.2Party 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 (1MAX_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[1MAX_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;in;++i){
			state ^=  (arry[i]  delim);
		}
		if(check(state)){//验证状态是否合法,合法则打印
			result[state] = 1;
		}
		return;		
	}
	for(i=0;iMAX_BUTTON;++i){
		arry[k]=buttons[i];
		search(k+1,n);
	}
}
void output(int state){
	for(int i=0;ilamp_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(1MAX_L);++i){//输出
		if(result[i]){
			output(i);
			flag = true;
		}
	}
	if(!flag)
		printf("IMPOSSIBLE\n");
	return 0;
}


 

最新回复(0)
/jishuHDA2h57QYmWRAVwGdKZnpT6N0_2B_2FiY23U893yGk9jkDs_3D4858378
8 简首页