题目地址
和高斯消元解线性方程基本一致。 最后return 0前面的操作中&是判断这个未知数是否对这个方程有影响
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<iomanip> #include<cstdio> #define int long long #define sc scanf #define pf printf using namespace std; typedef pair<int,int> pii; typedef long long ll; typedef unsigned long long LL; const int INF = 0x3f3f3f3f; const double eps = 1e-8; const int mod = 10000; const int N = 210; int a[N][N]; int gauss(int n){ int c,r; for(c=1,r=1;c<=n;c++){ int t = r; for(int i=r;i<=n;i++) if(a[i][c]){最大为1,所以1就可 t = i; break; } if(!a[t][c]) continue; for(int i=c;i<=n+1;i++) swap(a[r][i],a[t][i]); for(int i=r+1;i<=n;i++) if(a[i][c]) for(int j=c;j<=n+1;j++) a[i][j] ^= a[r][j]; r ++; } if(r <= n){ for(int i=r;i<=n;i++) if(a[i][n+1]) return 2; return 1; } for(int i=n-1;i>0;i--) for(int j=i+1;j<=n;j++) a[i][n+1] ^= (a[j][n+1] & a[i][j]);//只有系数为1的话才有影响 return 0; } signed main(){ // IOS; #ifdef ddgo freopen("C:/Users/asus/Desktop/ddgoin.txt","r",stdin); #endif int n; cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n+1;j++) cin>>a[i][j]; int t = gauss(n); if(t == 0) for(int i=1;i<=n;i++) cout<<a[i][n+1]<<endl; else if(t == 1) cout<<"Multiple sets of solutions"<<endl; else cout<<"No solution"<<endl; return 0; }