2.2.4(wonderful)

/*
ID:18861501
LANG:C++
TASK:lamps
*/
/*------------------Header Files------------------*/
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <ctype.h>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <limits.h>
using namespace std;
/*------------------Definitions-------------------*/
#define LL long long
#define PI acos(-1.0)
#define INF 0x3F3F3F3F
/*---------------------Work-----------------------*/
//首先要明白同一个按钮,按两次的效果是一样的,所以共有16种方案
//其次所按的次序可以无视,且16种方案可以压缩到8种,所以可以打表(常量数组)(按从小到大排列)
//因为1+2+3=不按,但是这里并不考虑如:一次按键完成所有均为1的情况;三次实现2或3或4的情况(体现只需要过后台数据即可)!!
//这个电力系统有一个性质:每6个灯是一个循环!!!,所以只需将要求压缩至前六个即可(重视思维!!!)
//当自相矛盾时可以直接输出:IMPOSSIBLE
//要多注意求模得到0的情况分别考虑
int light[9][7]=
{
	0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,  //1
	0,0,0,1,1,1,0,  //2 and 4
	0,0,1,0,1,0,1,  //3
	0,0,1,1,0,1,1,  //4
	0,1,0,0,1,0,0,  //1 and 4
	0,1,0,1,0,1,0,  //2
	0,1,1,0,0,0,1,  //3 and 4
	0,1,1,1,1,1,1,  //no
};
int minnum[9]= {0,1,2,1,1,2,1,2,0};
int N,C;
int on[110],off[110];
int want[7];
void work()
{
	scanf("%d%d",&N,&C);
	int cnt=1;
	while(1)
	{
		scanf("%d",&on[cnt]);
		if(on[cnt]==-1) break;
		cnt++;
	}
	cnt--;
	memset(want,-1,sizeof(want));
	for(int i=1; i<=cnt; i++)
	{
		int n;
		if(on[i]%6==0) n=6;
		else n=on[i]%6;
		if(want[n]==-1) want[n]=1;
	}
	cnt=1;
	while(1)
	{
		scanf("%d",&off[cnt]);
		if(off[cnt]==-1) break;
		cnt++;
	}
	cnt--;
	for(int i=1; i<=cnt; i++)
	{
		int n;
		if(off[i]%6==0) n=6;
		else n=off[i]%6;
		if(want[n]==-1) want[n]=0;
		if(want[n]==1)
		{
			printf("IMPOSSIBLE\n");
			return;
		}
	}
	bool flag_all=false;
	for(int i=1; i<=8; i++)
	{
		bool flag=true;
		for(int j=1; j<=6; j++)
		{
			if(want[j]!=light[i][j]&&want[j]!=-1)
			{
				flag=false;
				break;
			}
		}
		if(flag&&minnum[i]<=C)
		{
			flag_all=true;
			for(int j=1; j<=N; j++)
			{
				if(j%6==0) printf("%d",light[i][6]);
				else printf("%d",light[i][j%6]);
			}
			printf("\n");
		}
	}
	if(!flag_all) printf("IMPOSSIBLE\n");
}
/*------------------Main Function------------------*/
int main()
{
	//freopen("test.txt","r",stdin);
	freopen("lamps.out","w",stdout);
	freopen("lamps.in","r",stdin);
	work();
	return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值