高斯消元 AcWing 884. 高斯消元解异或线性方程组

高斯消元 AcWing 884. 高斯消元解异或线性方程组

原题链接

AcWing 884. 高斯消元解异或线性方程组

算法标签

线性空间 高斯消元 异或

思路

高斯消元 AcWing 884. 高斯消元解异或线性方程组_第1张图片

代码

#include
#define int long long
#define abs fabs
#define rep(i, a, b) for(int i=a;i=b;--i)
using namespace std;
const int N = 105;
int a[N][N], eps = 1e-8;
int n;
inline int read(){
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put(int x) {
    if(x<0) putchar('-'),x=-x;
    if(x>=10) put(x/10);
    putchar(x%10^48);
}
int gu(){// 高斯消元,答案存于a[i][n]中,0 <= i < n
    // c代表列 r代表行
    int c, r;
    // 按列枚举
    for(c=0, r=0; ceps){
                return 2;// 无解
            }
        }
        return 1;// 有无穷多组解
    }
    Rep(i, n-1, 0){
        rep(j, i+1, n){
            a[i][n]^=a[i][j]*a[j][n];
        }
    }
    return 0;// 有唯一解
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    n=read();
    rep(i, 0, n){
        rep(j, 0, n+1){
            a[i][j]=read();
        }
    }
    int t=gu();
    if(t==2){
        puts("No solution");
    }else if(t==1){
        puts("Multiple sets of solutions");
    }else{
        rep(i, 0, n){
            printf("%lld\n", a[i][n]);
        }
    }
    return 0;
}

原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
在这里插入图片描述

你可能感兴趣的:(算法,c++,算法,开发语言)