#7 //[CQOI2014]和谐矩阵
题解:
bitset优化高斯消元
无关变量为1
#include <bits/stdc++.h> using namespace std; #define eps 1e-9 #define N 1610 bitset<N> a[N]; int n; void Gause() { for (int i=0;i<n;i++) { int now=i; for (int j=i;j<n;j++) if (a[j][i]>a[now][i]) now=j; if (a[now][i]) { swap(a[i],a[now]); for (int j=0;j<n;j++) if (j!=i&&a[j][i]) a[j]^=a[i]; } else { for (int j=0;j<n;j++) if (a[j][i]) a[j][i]=0,a[j][n]=a[j][n]^1; } } } #define js(x,y) (x-1)*m1+y-1 #define pd(x,y) if (x>=1&&x<=n1&&y>=1&&y<=m1) int dx[5]={0,1,0,-1,0}; int dy[5]={0,0,1,0,-1}; int main() { freopen("noi.in","r",stdin); freopen("noi.out","w",stdout); std::ios::sync_with_stdio(false); int n1,m1; cin>>n1>>m1; n=n1*m1; for (int i=1;i<=n1;i++) for (int j=1;j<=m1;j++) for (int k=0;k<=4;k++) pd(i+dx[k],j+dy[k]) { a[js(i,j)][js(i+dx[k],j+dy[k])]=1; } Gause(); for (int i=1;i<=n1;i++) { for (int j=1;j<=m1;j++) { int x=js(i,j); if (!a[x][x]|a[x][n]) cout<<1<<" "; else cout<<0<<" "; } cout<<endl; } return 0; }