USACO Party Lamps
2015-03-08 15:41
197 查看
题目大意:一排灯有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=1;i<=n;i++)lamp[i]^=1; } void but2(int n) { for(int i=1;i<=n;i+=2)lamp[i]^=1; } void but3(int n) { for(int i=2;i<=n;i+=2)lamp[i]^=1; } void but4(int n) { for(int i=0;i*3+1<=n;i++)lamp[i*3+1]^=1; } int check(int n,int c,int count_now) { for(int i=1;i<n1;i++)if(lamp[a[i]]==0)return 0; for(int i=1;i<n2;i++)if(lamp[b[i]]==1)return 0; if(count_now>c)return 0; int u=c-count_now; if(u&1)return 0; return 1; } int cmp(T x, T y) { return strcmp(x.ch+1,y.ch+1)>=0?false:true; } int main() { int n,c; fin>>n>>c; while(fin>>a[++n1]&&a[n1]!=-1); while(fin>>b[++n2]&&b[n2]!=-1); for(int i=1;i<=n;i++)temp[i]=1; int h=0; for(int i=0;i<=(1LL<<4)-1;i++) { int count_now=0; memcpy(lamp,temp,sizeof(lamp)); for(int j=1,idx=1;j<=i;j<<=1,idx++)if((i&j)!=0 ) { count_now++; if(idx==1)but1(n); if(idx==2)but2(n); if(idx==3)but3(n); if(idx==4)but4(n); } if(check(n,c,count_now)) { h++; for(int i=1;i<=n;i++) { ans[h].ch[i]=lamp[i]+'0'; } } } if(h==0)fout<<"IMPOSSIBLE"<<endl;else { sort(ans+1,ans+1+h,cmp); for(int i=1;i<=h;i++)fout<<ans[i].ch+1<<endl; } return 0; }
相关文章推荐
- USACO 2.2.4 Party Lamps
- USACO 2.2.4 Party Lamps 解题报告
- usaco2.2.4 Party Lamps
- usaco Party Lamps
- usaco Party Lamps report
- USACO : Party Lamps dfs 深搜
- USACO section 2.2 Party Lamps
- USACO:2.2.4 Party Lamps 派对灯
- Party Lamps_usaco2.2.4_暴力?
- USACO section 2.2 Party Lamps
- USACO2.2.4--Party Lamps
- usaco2.24Party Lamps
- USACO 2.2.4 Party Lamps
- JZOJ1265.【USACO题库】2.2.4 Party Lamps派对灯
- USACOTrainning.Party Lamps
- USACO 2.2Party Lamps
- usaco party lamps
- USACO 2.2.4 Party Lamps 题解
- usaco Party Lamps
- USACO :Party Lamps解题报告