#include <stdio.h> int main() { puts("转载请注明出处"); puts("地址:blog.csdn.net/vmurder/article/details/43699831"); }
题解:
随便搞搞就好。
自由元全当成1就好了么~~~
不会异或方程组的移步这里【POJ1222】EXTENDED LIGHTS OUT 高斯消元、解异或方程组
代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define P 45 #define N 1800 using namespace std; const int dx[]={0,0,0,1,-1}; const int dy[]={0,1,-1,0,0}; int a[N][N],x[N]; int crs[N]; void Gauss(int n,int m) { int i,j,k,id; for(id=i=1;i<=m;i++,id++) { for(j=id;j<=n&&!a[j][i];j++); if(j>n){id--;continue;} else crs[id]=i; if(id!=j)for(k=i;k<=m;k++)swap(a[id][k],a[j][k]); for(j=id+1;j<=n;j++)if(a[j][i])for(k=i;k<=m;k++) a[j][k]^=a[id][k]; }id--; for(i=m;i;i--) { if(i!=crs[id]){x[i]=1;continue;} int ret=a[id][n]; for(j=m;j>i;j--)if(a[id][j])ret^=x[j]; x[i]=ret; id--; } } int n,m; int id[P][P],cnt; int main() { freopen("test.in","r",stdin); int i,j,k; int tx,ty; scanf("%d%d",&n,&m); for(i=1;i<=n;i++)for(j=1;j<=m;j++)id[i][j]=++cnt; for(i=1;i<=n;i++)for(j=1;j<=m;j++)for(k=0;k<=4;k++) if(id[tx=i+dx[k]][ty=j+dy[k]])a[id[i][j]][id[tx][ty]]=1; Gauss(cnt+1,cnt); cnt=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++)printf("%d ",x[++cnt]); puts(""); } return 0; }