枚舉_百煉 2811 熄燈問題 (美妙的枚舉函數)
阿新 • • 發佈:2018-01-30
ret tdi names gpo == algo turn crt secure
1 #define _CRT_SECURE_NO_WARNINGS 2 #include <stdio.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <stdlib.h> 6 #include <vector> 7 #include <map> 8 #include <queue> 9 #include <string> 10 #include <iostream> 11 #include <ctype.h> 12#include <string.h> 13 #include <set> 14 #include <stack> 15 #include<functional> 16 using namespace std; 17 #define Size 110 18 #define maxn 1<<30 19 #define minn 1e-6 20 int a[6][8]; 21 int press[6][8]; 22 bool guest(){ 23 for (int i = 1; i < 5; i++){ 24 for(int j = 1; j <= 6; j++){ 25 press[i + 1][j] = (a[i][j] + press[i][j] + press[i - 1][j] + press[i][j - 1] + press[i][j + 1]) % 2; 26 } 27 /* 28 按不按[4][3] 取決於[3][3]的狀態, 等於號後面的是現在(3,3)的狀態 29 */ 30 } 31 for (int i = 1; i <= 6; i++){ 32 if(a[5][i] != (press[5][i] + press[4][i] + press[5][i - 1] + press[5][i + 1]) % 2) return false; 33 } 34 return true; 35 } 36 void solve(){ 37 int c; 38 while (guest() == false){ 39 c = 1; 40 press[1][1]++; 41 while (press[1][c] > 1){ 42 press[1][c] = 0; 43 c++; 44 press[1][c]++; 45 } 46 } 47 /* 48 美妙的枚舉函數 49 0 50 1 51 01 52 11 53 001 54 101 55 011 56 111 57 0001 58 */ 59 for (int i = 1; i <= 5; i++){ 60 for (int j = 1; j <= 6; j++) 61 if (j == 1) cout << press[i][j]; 62 else cout << " " << press[i][j]; 63 cout << endl; 64 } 65 66 } 67 int main(){ 68 for (int i = 1; i <= 5; i++) 69 for (int j = 1; j <= 6; j++) 70 cin >> a[i][j]; 71 solve(); 72 system("pause"); 73 }
枚舉_百煉 2811 熄燈問題 (美妙的枚舉函數)