百练2811:熄灯问题
题目链接:http://bailian.openjudge.cn/practice/2811/
#include <cstdio> int press[6][7]; int puzzle[6][7]; bool guess(){ for(int i = 1;i < 5;i++) for(int j = 1;j < 7;j++) press[i+1][j] = (puzzle[i][j] + press[i][j] + press[i-1][j] + press[i][j-1] + press[i][j+1])%2; for(int j = 1;j < 7;j++) if((press[5][j] + press[5][j-1] + press[4][j] + press[5][j+1])%2 != puzzle[5][j]) return false; return true; } void enumerate(){ //00000 100000 01000 11000 001000 101000 int c; for(c = 1;c < 7;c++) press[1][c] = 0; while(guess()==false){ press[1][1] ++; c = 1; while(press[1][c] > 1){ press[1][c] = 0; c++; press[1][c]++; } } return; } int main(){ //int t; //scanf("%d",&t); //for(int p = 1;p <= t;p++){ for(int i = 1;i < 7;i++) press[0][i] = 0; for(int i = 1;i < 6;i++){ press[i][0] = 0; press[i][7] = 0; } for(int i = 1;i < 6;i++) for(int j = 1;j < 7;j++) scanf("%d",&puzzle[i][j]); enumerate(); //printf("PUZZLE #%d\n",p); for(int r = 1; r < 6; r++ ) { for (int c = 1; c < 7; c++ ) printf("%d ",press[r][c]); printf("\n"); } //} return 0; }