POJ 1222-extended lights out (Gaussian elimination element for solving equations)
There is a matrix of 5*6. Each position indicates a button and a light. 1 indicates bright, and 0 indicates extinction. Every time you press the button at the next position, it switches all the states of the lights around it (the question shows how it affects ), ask which buttons can be pressed in such a square matrix to turn the entire square matrix out. In this case, 1 indicates that the square is pressed, and 0 indicates that the square is not pressed.
#include
#include
#include
#include
#include
#include
#include #include
#include
#include
#include
using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const double pi= acos(-1.0);const double esp=1e-6;const int MAXN=40;int aug[MAXN][MAXN];int x[MAXN];int m,n;int dx[]= {0,0,1,0,-1};int dy[]= {0,1,0,-1,0};int Gauss() { int i,j; int row,col,max_r; int tmp; for(row=0,col=0; row
abs(aug[max_r][col])) max_r=i; } if(max_r!=row) { for(j=row; j
=0; i--) { x[i]=aug[i][n]; for(j=i+1; j
=0&&x<5&&y>=0&&y<6) { aug[i*6+j][x*6+y]=1; } } Gauss(); printf(PUZZLE #%d,icase++); for(i=0; i<30; i++) { if(i%6!=0) printf( %d,x[i]); else printf(%d,x[i]); } puts(); } return 0;}