USACO Party Lamps

时间:2022-07-19 07:34:14

题目大意:一排灯有n个,有4种开关,每种开关能改变一些灯现在的状态(亮的变暗,暗的变亮)现在已知一些灯的亮暗情况,问所以可能的情况是哪些

思路:同一种开关开两次显然是没效果的,那么枚举每个开关是否开就好了,还是暴力大法好

 /*{
ID:a4298442
PROB:lamps
LANG:C++
}
*/
#include<iostream>
#include<fstream>
#include<cstring>
#include<algorithm>
#define maxn 109
using namespace std;
ifstream fin("lamps.in");
ofstream fout("lamps.out");
//#define fin cin
//#define fout cout
int lamp[maxn],temp[maxn],n1,n2,a[maxn],b[maxn];
struct T
{
char ch[maxn];
}ans[maxn];
void but1(int n)
{
for(int i=;i<=n;i++)lamp[i]^=;
}
void but2(int n)
{
for(int i=;i<=n;i+=)lamp[i]^=;
}
void but3(int n)
{
for(int i=;i<=n;i+=)lamp[i]^=;
}
void but4(int n)
{
for(int i=;i*+<=n;i++)lamp[i*+]^=;
}
int check(int n,int c,int count_now)
{
for(int i=;i<n1;i++)if(lamp[a[i]]==)return ;
for(int i=;i<n2;i++)if(lamp[b[i]]==)return ;
if(count_now>c)return ;
int u=c-count_now;
if(u&)return ;
return ;
}
int cmp(T x, T y)
{
return strcmp(x.ch+,y.ch+)>=?false:true;
}
int main()
{
int n,c;
fin>>n>>c;
while(fin>>a[++n1]&&a[n1]!=-);
while(fin>>b[++n2]&&b[n2]!=-);
for(int i=;i<=n;i++)temp[i]=;
int h=;
for(int i=;i<=(1LL<<)-;i++)
{
int count_now=;
memcpy(lamp,temp,sizeof(lamp));
for(int j=,idx=;j<=i;j<<=,idx++)if((i&j)!= )
{
count_now++;
if(idx==)but1(n);
if(idx==)but2(n);
if(idx==)but3(n);
if(idx==)but4(n);
}
if(check(n,c,count_now))
{
h++;
for(int i=;i<=n;i++)
{
ans[h].ch[i]=lamp[i]+'';
}
}
}
if(h==)fout<<"IMPOSSIBLE"<<endl;else
{
sort(ans+,ans++h,cmp);
for(int i=;i<=h;i++)fout<<ans[i].ch+<<endl;
}
return ;
}