从原理上来讲 ,,, 这是个高斯消元的题目 , 但数据也太弱 , 最裸的暴搜就可以啊...........
//
// main.cpp
// UVa 1560
//
// Created by Fuxey on 15/10/25.
// Copyright © 2015年 corn.crimsonresearch. All rights reserved.
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
int g[10][10];
int now[10][10] , times[10][10];
bool dfs(int i , int j)
{
if(j==7) return dfs(i+1 , 1);
if(i==6 && j==1)
{
bool ok = true;
for(int k=1;k<=6;k++) if((g[5][k]+times[5][k])%2) { ok = false; break; }
return ok;
}
for(int k=0;k<2;k++)
{
now[i][j] = k;
if(k) { times[i][j]++; times[i-1][j]++; times[i+1][j]++; times[i][j-1]++; times[i][j+1]++; }
if(!(i!=1 && (times[i-1][j]+g[i-1][j])%2!=0)) if(dfs(i, j+1)) return true;// decide g[i-1][j] is legal?
if(k) { times[i][j]--; times[i-1][j]--; times[i+1][j]--; times[i][j-1]--; times[i][j+1]--; }
}
return false;
}
int main(int argc, const char * argv[]) {
int t;
cin>>t;
for(int Case=1;Case<=t;Case++)
{
for(int i=1;i<=5;i++) for(int j=1;j<=6;j++) cin>>g[i][j];
memset(times, 0, sizeof(times));
dfs(1 , 1);
cout<<"PUZZLE #"<<Case<<endl;
for(int i=1;i<=5;i++) for(int j=1;j<=6;j++) cout<<now[i][j]<<(j==6?"\n":" ");
}
return 0;
}