POJ1222

来源:互联网 发布:阿里云服务器公网ip 编辑:程序博客网 时间:2024/05/22 10:36

熄灯问题,枚举问题

只需枚举第一行

#include "iostream"using namespace std;const int N = 64;int Bubble[7][8];int Action[7][8];bool GetAnswer(void){for(int Row = 1 ; Row != 5 ; Row ++){for (int Col = 1 ; Col != 7 ; Col ++){Action[Row + 1][Col] = ( Action[Row][Col] + Action[Row][Col - 1] + Action[Row - 1][Col] + Action[Row][Col + 1] + Bubble[Row][Col] ) % 2;}}for ( int Col = 1 ; Col != 7 ; Col ++ ){if ( ( Action[5][Col] + Action[5][Col - 1] + Action[4][Col] + Action[5][Col + 1] + Bubble[5][Col] ) % 2 != 0 ){return false;}}return true;}void SetFirstLine(void){for (int i = 1 ; i != 7 ; i ++){Action[1][i] = 0;}for (int i = 0 ; i != N ; i ++ ){int Test = i;int Bita = 1;while(Test != 0){Action[1][Bita ++] = Test % 2;Test /= 2;}if(GetAnswer() == true)break;}}int main(void){int Case,Count = 0;cin >> Case;while(Case --){for ( int i = 1 ; i != 6 ; i ++ ){for ( int j = 1 ; j != 7 ; j ++ ){cin >> Bubble[i][j];}}SetFirstLine();Count ++;cout << "PUZZLE #" << Count << endl;for ( int i = 1 ; i != 6 ; i ++ ){for ( int j = 1 ; j != 7 ; j ++ ){cout << Action[i][j] << " ";}cout << endl;}}return 0;}


 

原创粉丝点击