USACO 2.2 Party Lamps
来源:互联网 发布:想开淘宝没有货 编辑:程序博客网 时间:2024/05/16 00:57
题目:To brighten up the gala dinner of the IOI'98 we have a set of N (10 <= N <= 100) colored lamps numbered from 1 to N.
The lamps are connected to four buttons:
- Button 1: When this button is pressed, all the lamps change their state: those that are ON are turned OFF and those that are OFF are turned ON.
- Button 2: Changes the state of all the odd numbered lamps.
- Button 3: Changes the state of all the even numbered lamps.
- Button 4: Changes the state of the lamps whose number is of the form 3xK+1 (with K>=0), i.e., 1,4,7,...
A counter C records the total number of button presses.
When the party starts, all the lamps are ON and the counter C is set to zero.
You are given the value of counter C (0 <= C <= 10000) and the final state of some of the lamps after some operations have been executed. Write a program to determine all the possible final configurations of the N lamps that are consistent with the given information, without repetitions.
PROGRAM NAME: lamps
INPUT FORMAT
No lamp will be listed twice in the input.
Line 1:NLine 2:Final value of CLine 3:Some lamp numbers ON in the final configuration, separated by one space and terminated by the integer -1.Line 4:Some lamp numbers OFF in the final configuration, separated by one space and terminated by the integer -1.SAMPLE INPUT (file lamps.in)
101-17 -1
In this case, there are 10 lamps and only one button has been pressed. Lamp 7 is OFF in the final configuration.
OUTPUT FORMAT
Lines with all the possible final configurations (without repetitions) of all the lamps. Each line has N characters, where the first character represents the state of lamp 1 and the last character represents the state of lamp N. A 0 (zero) stands for a lamp that is OFF, and a 1 (one) stands for a lamp that is ON. The lines must be ordered from least to largest (as binary numbers).
If there are no possible configurations, output a single line with the single word `IMPOSSIBLE'
SAMPLE OUTPUT (file lamps.out)
000000000001010101010110110110In this case, there are three possible final configurations:
- All lamps are OFF
- Lamps 1, 4, 7, 10 are OFF and lamps 2, 3, 5, 6, 8, 9 are ON.
- Lamps 1, 3, 5, 7, 9 are OFF and lamps 2, 4, 6, 8, 10 are ON.
/*ID: gjj50201LANG: C++TASK: lamps*/#include<stdio.h>#include<iostream>#include<string.h>#include<cmath>#include<vector>#include<algorithm>#define b1 63#define b2 21#define b3 42#define b4 9using namespace std;int N,C;int light[64];int mark[6];vector <string> ans;//搜索c步能达到的所有可能状态void dfs(int k, int steps){if(!steps){light[k] = 1;return;}int t;t = k^b1; dfs(t,steps-1);t = k^b2; dfs(t,steps-1);t = k^b3; dfs(t,steps-1);t = k^b4; dfs(t,steps-1);}//检查是否满足题目要求的限制条件int ok(int k){for(int i=0;i<6;i++)if( mark[i]!=-1 && (k&(1<<i)) != (mark[i]<<i))return 0;return 1;}//扩展成需要的N位串string convert(int k){int ans[6];//把十进制转化成二进制,并且相应位子上的数字存起来for(int i=0;i<6;i++) ans[i] = (k & (1<<i)) / (1<<i); string result = "";for(int i = 0; i<N ;i++)result += ans[i%6] + '0'; return result;}int main(){freopen("lamps.in","r",stdin); freopen("lamps.out","w",stdout); cin>>N>>C; while(C>4) C-=2; for(int i=0;i<6;i++) mark[i] = -1; int tmp; cin>>tmp; while(tmp!=-1) {mark[(tmp-1)%6] = 1; cin>>tmp;} cin>>tmp; while(tmp!=-1) {mark[(tmp-1)%6] = 0; cin>>tmp;} dfs(63,C); for(int i=0;i<64;i++) if(light[i] && ok(i)) ans.push_back(convert(i)); if(!ans.size()) cout<<"IMPOSSIBLE"<<endl; else{ sort(ans.begin(),ans.end()); vector<string>::iterator it; for(it = ans.begin();it!=ans.end();it++) cout<<*it<<endl; } return 0;}
- USACO 2.2 Party Lamps (lamps)
- USACO 2.2 Party Lamps
- USACO 2.2 Party Lamps
- USACO 2.2Party Lamps
- USACO 2.2 Party Lamps
- USACO Section 2.2 Party Lamps
- USACO 2.2.4 Party Lamps
- [USACO 2.2.4] Party Lamps
- USACO section 2.2 Party Lamps
- USACO 2.2.4 Party Lamps
- USACO 2.2.4 Party Lamps
- USACO Section 2.2 Party Lamps
- USACO 2.2.4 Party Lamps
- USACO Section 2.2 Party Lamps
- USACO 2.2.4 Party Lamps
- USACO:2.2.4 Party Lamps 派对灯
- USACO-Section 2.2 Party Lamps (枚举)
- [2016/7/26][usaco 2.2]Party Lamps
- 【学渣告诉你】到底神马是傅里叶级数!!!!!!
- Java面试题全集(下)
- Servlet.service() for servlet jsp threw exception The Struts dispatcher cannot be found.
- 2017-04-05 DBA日记,oracle增量备份实施
- 1058 合唱队形
- USACO 2.2 Party Lamps
- ROC和AUC介绍以及如何计算AUC
- poi到处数据 使用反射机制 动态取字段数据
- 利用IntelliJ IDEA与Maven开始你的Scala之旅
- 出现错误“tcnative-1.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform”的解决办法
- 第一章11
- resin容器发布的jsp项目在访问时,提示Check that you are using the JDK, not the JRE.
- TensorBoard tf.summary.merge_all() AttributeError: 'NoneType' object has no attribute 'bucket 错误
- 解解request乱码问题