(传送门)
题意:
中文题,这里就不说了
解题思路
这道题目可以说是一道非常裸的高斯消元,高斯消元大家概念要清楚,非常简单,就是转换为上三角,然后直接求解,学过线性代数的,这个高斯消元可以直接手写的,没有难度 对于这道题目,直接建立方程组,方程所建立的条件就是相互影响的快,由于是变亮所以是对 2 <script type="math/tex" id="MathJax-Element-14">2</script>取模,异或位操作可以代替
代码
#include <cstdio> #include <cstring> #include <algorithm> #define FIN freopen("input.txt", "r", stdin) using namespace std; const int SIZE = 10; char game[SIZE][SIZE]; int gas[SIZE * SIZE][SIZE * SIZE]; int dc[4] = {1,0,-1,0}; int dr[4] = {0,1,0,-1}; int X[SIZE * SIZE]; int gcd(int a, int b){ return b ? gcd(b, a % b) : a; } int lcm(int a, int b){ return a / gcd(a, b) * b; } void gauss(int equ, int cnt){ int max_r, col, row; memset(X, 0, sizeof(X)); for(col = 0, row = 0;row < equ && col < cnt; row ++, col ++){ max_r = row; for(int i = row + 1;i < equ;i ++){ if(abs(gas[i][col]) > abs(gas[max_r][col])) max_r = i; } if(max_r != row){ for(int j = 0;j < cnt + 1;j ++){ swap(gas[max_r][j], gas[row][j]); } } if(gas[row][col] == 0){ row --; continue; } for(int i = row + 1;i < equ;i ++){ if(gas[i][col] != 0){ for(int j = col;j < cnt + 1;j ++){ gas[i][j] ^= gas[row][j]; } } } } for(int i = cnt - 1;i >= 0;i --){ X[i] = gas[i][cnt]; for(int j = i + 1;j < cnt;j ++){ X[i] ^= gas[i][j] * X[j]; } } } int main() { //FIN; while(~scanf("%s", game[0])) { for(int i = 1; i < 5; i ++) { scanf("%s", game[i]); } int cnt = 5 * 6; memset(gas, 0, sizeof(gas)); for(int i = 0; i < cnt; i ++) { int row = i / 6; int col = i % 6; if(game[row][col] == '0') gas[i][cnt] = 1; gas[i][i] = 1; for(int j = 0;j < 4;j ++){ int ncol = col + dc[j]; int nrow = row + dr[j]; if(ncol < 0 || nrow < 0 || ncol >= 6 || nrow >= 5) continue; gas[i][nrow * 6 + ncol] = 1; } } gauss(cnt, cnt); int ans = 0; for(int i = 0;i < cnt;i ++){ if(X[i]) ans ++; } printf("%d\n", ans); for(int i = 0;i < cnt;i ++){ if(X[i]){ printf("%d %d\n", i / 6 + 1, i % 6 + 1); } } } return 0; }