# POJ 1222 EXTENDED LIGHTS OUT （异或消元）

c[i] xor (a[i][0]x[0]) xor (a[i][1]x[1]) xor ... xor (a[i][29]x[29])=0(a[i][0]x[0]) xor (a[i][1]x[1]) xor ... xor (a[i][29]x[29])=0 xor c[i]

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
#define FOR(i,x,y)  for(int i = x;i < y;++ i)
#define IFOR(i,x,y) for(int i = x;i > y;-- i)

using namespace std;

const int maxn = 30;

int a[maxn];
int n,mat[5][6],c[30];

void init(){
FOR(i,0,5){
FOR(j,0,6)  scanf("%d",&mat[i][j]),c[6*i+j] = 0^mat[i][j];
}
FOR(i,0,5){
FOR(j,0,6){
int u = i*6+j;
a[u] = (1<<(30-u))^c[u];
if(i > 0)   a[u] ^= (1<<(36-u));
if(i < 4)   a[u] ^= (1<<(24-u));
if(j > 0)   a[u] ^= (1<<(31-u));
if(j < 5)   a[u] ^= (1<<(29-u));
}
}
}

int xorguass(int n){
int row = 0;
for(int i = 30;i >= 0;-- i){
int j;
for(j = row;j < n;++ j){
if(a[j] & (1<<i))   break;
}
if(j != n){
swap(a[j],a[row]);
for(j = 0;j < n;++ j){
if(j == row)    continue;
if(a[j] & (1<<i))   a[j] ^= a[row];
}
}
++ row;
}
return row;
}

int ans[5][6];

void work(){
int n = xorguass(30);
FOR(i,n,30) a[i] = 0;
FOR(i,0,30){
ans[i/6][i%6] = a[i]%2;
}
FOR(i,0,5){
FOR(j,0,5)  printf("%d ",ans[i][j]);
printf("%d\n",ans[i][5]);
}
}

int main()
{
//freopen("test.in","r",stdin);
int T,tCase = 0;    scanf("%d",&T);
while(T--){
printf("PUZZLE #%d\n",++tCase);
init();
work();
}
return 0;
}


#### POJ-1222 EXTENDED LIGHTS OUT(高斯消元)

2015-08-10 14:19:53

#### POJ 1222 EXTENDED LIGHTS OUT(矩阵反转问题——枚举or高斯消元)

2016-02-16 20:22:14

#### pku 1222 EXTENDED LIGHTS OUT（构造矩阵+高斯消元）

2013-07-29 13:04:39

#### POJ 1222 : EXTENDED LIGHTS OUT

2012-04-25 15:45:22

#### poj 1222 EXTENDED LIGHTS OUT

2016-09-05 21:38:58

#### POJ 1222 EXTENDED LIGHTS OUT

2014-07-10 00:36:46

#### POJ 1222 EXTENDED LIGHTS OUT

2014-08-07 09:52:45

#### poj(1222)——EXTENDED LIGHTS OUT

2016-03-15 21:45:32

#### POJ 1222 EXTENDED LIGHTS OUT

2014-08-26 19:49:42

#### poj 1222:EXTENDED LIGHTS OUT

2014-06-23 09:19:52