写这道题目的时候遇到了一个令人诧异的问题,就是平台上跑来的结果和我本机跑起来的结果不一样。

后来Debug了之后才发现是我数组开小了,只开到100 的数组竟然都去访问他170位的地址肯定要跪成翔啊...

好吧,解释一下题意。

有N盏台灯,C次操作

每次操作可以按一次按钮,一共一个四个按钮

可以得出的规律是每6个台灯是一次循环。

易得证。(其实不难发现Button 1 不用考虑,Button 2 和 Button 3 对立, 那么Button 4 的作用就是让1, 4, 7, 11改变状态

那么可以发现 7 和 1 其实是一模一样的,他们都受Button 1, 3, 4操控,依次类推即可)

还不会用BitSet来写这道题目...得学习一下了,我只开了个数组sta_ans[w][i][j][k][l][m][n] 来代表第w次操作后,后面六个代表的是二进制

这样的话每次访问都是O(1)的效率会非常快

结果:

USER: Jeremy Wu [wushuai2]
TASK: lamps
LANG: C++ Compiling...
Compile: OK Executing...
Test 1: TEST OK [0.011 secs, 5996 KB]
Test 2: TEST OK [0.005 secs, 5996 KB]
Test 3: TEST OK [0.005 secs, 5996 KB]
Test 4: TEST OK [0.005 secs, 5996 KB]
Test 5: TEST OK [0.005 secs, 5996 KB]
Test 6: TEST OK [0.005 secs, 5996 KB]
Test 7: TEST OK [0.003 secs, 5996 KB]
Test 8: TEST OK [0.005 secs, 5996 KB] All tests OK.
/*
ID: wushuai2
PROG: lamps
LANG: C++
*/
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max(a,b) (((a) > (b)) ? (a) : (b))
#define Min(a,b) (((a) < (b)) ? (a) : (b))
#define Abs(x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0)
#define RV(num) ((num) > 0 ? 0 : 1) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template<class T> inline void checkmin(T &a,T b){if(a>b) a=b;}
template<class T> inline void checkmax(T &a,T b){if(a<b) a=b;} const double eps = 1e- ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ;
const int MAX_N = ;
const int MAXSIZE = ; int N, C;
int ans[], sum;
int sta_ans[][][][][][][]; bool check(int i, int j, int k, int l, int m, int n){
int aaa[] = {, i, j, k, l, m, n};
for(int ii = ; ii < ; ++ii){
if(ans[ii] == - || aaa[ii] == ans[ii]){
continue;
} else return false;
}
return true;
} int main() {
ofstream fout ("lamps.out");
ifstream fin ("lamps.in");
int i, j, k, l, m, n, t, s, c, w, q, num;
memset(ans, -, sizeof(ans));
fin >> N;
fin >> C;
while(fin >> num){
if(- == num) break;
if(num % == ) ans[] = ;
else ans[num % ] = ;
}
while(fin >> num){
if(- == num) break;
if(num % == ) ans[] = ;
else ans[num % ] = ;
} sta_ans[][][][][][][] = ;
for(w = ; w <= C; ++w){
for(i = ; i < ; ++i){
for(j = ; j < ; ++j){
for(k = ; k < ; ++k){
for(l = ; l < ; ++l){
for(m = ; m < ; ++m){
for(n = ; n < ; ++n){
if(sta_ans[w - ][i][j][k][l][m][n] == ){
sta_ans[w][RV(i)][RV(j)][RV(k)][RV(l)][RV(m)][RV(n)] = ;
sta_ans[w][i][RV(j)][k][RV(l)][m][RV(n)] = ;
sta_ans[w][RV(i)][j][RV(k)][l][RV(m)][n] = ;
sta_ans[w][RV(i)][j][k][RV(l)][m][n] = ;
} }
}
}
}
}
} }
for(i = ; i < ; ++i){
for(j = ; j < ; ++j){
for(k = ; k < ; ++k){
for(l = ; l < ; ++l){
for(m = ; m < ; ++m){
for(n = ; n < ; ++n){
if(check(i, j, k, l, m, n)){
if(sta_ans[C][i][j][k][l][m][n] == ){
++sum;
for(int ii = ; ii <= N; ++ii){
if(ii % == ){
fout << n;
} else if(ii % == ){
fout << i;
} else if(ii % == ){
fout << j;
} else if(ii % == ){
fout << k;
} else if(ii % == ){
fout << l;
} else if(ii % == ){
fout << m;
}
}
fout << endl;
}
} }
}
}
}
}
}
if(!sum){
fout << "IMPOSSIBLE" << endl;
} fin.close();
fout.close();
return ;
}

USACO Party Lamps 【Binary code solvution】【规律】的更多相关文章

  1. URAL 1780 G - Gray Code 找规律

    G - Gray CodeTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view ...

  2. @gym - 101190B@ Binary Code

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 我们称一组字符串是 "前缀码",当且仅当不存 ...

  3. POJ 1850 Code(找规律)

    Code Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 7913   Accepted: 3709 Description ...

  4. BZOJ4840 NEERC2016 Binary Code

    Problem BZOJ Solution 可能是因为快要省选了,所以最近更博的频率好像高了点_(:зゝ∠)_ 每个字符串最多有两个状态,然后要满足一些依赖关系,考虑2sat.可以先把字符串的结束节点 ...

  5. USACO Party Lamps

    题目大意:一排灯有n个,有4种开关,每种开关能改变一些灯现在的状态(亮的变暗,暗的变亮)现在已知一些灯的亮暗情况,问所以可能的情况是哪些 思路:同一种开关开两次显然是没效果的,那么枚举每个开关是否开就 ...

  6. 格雷码(Gray Code)转二进制码(Binary Code)

    学习verilog generate语句时,偶然看到用generate语句来进行格雷码到二进制码转换的代码,就从网上找了一些案例来学习. 下表为几种自然二进制码与格雷码的对照表: 十进制数 自然二进制 ...

  7. 格雷码Gray Code详解

    格雷码简介 在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同,则称这种编码为格雷码(Gray Code),另外由于最大数与最小数之间也仅一位数不同,即“首尾相连”,因此又称循环码或反射码.格 ...

  8. Adaptive Code Via C#读书笔记

    原书链接: http://www.amazon.com/Adaptive-Code-via-principles-Developer-ebook/dp/B00OCLLYTY/ref=dp_kinw_s ...

  9. [LeetCode]题解(python):089 Gray Code

    题目来源 https://leetcode.com/problems/gray-code/ The gray code is a binary numeral system where two suc ...

随机推荐

  1. C# Convert an enum to other type of enum

    Sometimes, if we want to do convert between two enums, firstly, we may think about one way: var myGe ...

  2. 精通UNIX下C语言编程与项目实践

    cc  -I  //include 目录 -L //静态库目录?动态也可以 -l //小写L,接静态库名称?动态也可以 -DXXX='"XXFF"' //-D直接定义宏 -c 只编 ...

  3. android 百度最新地图sdk包怎么去除 放大缩小按钮

    // 隐藏缩放控件 int childCount = mMapView.getChildCount(); View zoom = null; ; i < childCount; i++) { V ...

  4. HDU 1847 Good Luck in CET-4 Everybody!

    题解:巴什博弈,2^k+1=3N或2^k2=3N,所以3N为P-position,3N+r为N-position. #include <cstdio> int main(){ int n; ...

  5. SPOJ1811最长公共子串问题(后缀自动机)

    题目:http://www.spoj.com/problems/LCS/ 题意:给两个串A和B,求这两个串的最长公共子串. 分析:其实本题用后缀数组的DC3已经能很好的解决,这里我们来说说利用后缀自动 ...

  6. codeforces#FF DIV2C题DZY Loves Sequences(DP)

    题目地址:http://codeforces.com/contest/447/problem/C C. DZY Loves Sequences time limit per test 1 second ...

  7. Objective-c @property和@Synthesize

    在Objective-c中,使用@property来标识属性(一般是实例变量).在实现文件中使用@synthesize标识所声明的变量,让系统自动生成设置方法和获取方法. 也就是说@property和 ...

  8. C# inherit

    Case:class A has a construct. class B is inherit from class A and B also has a construct. What's the ...

  9. 【ActiveMQ】设置自动重连

    <property name="brokerURL" value="tcp://localhost:61616"/> <property na ...

  10. CheckBox控件实现选项的选中

    1:设置控件属性 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...