当前位置:网站首页>Gaussian elimination acwing 884. Gaussian elimination for solving XOR linear equations
Gaussian elimination acwing 884. Gaussian elimination for solving XOR linear equations
2022-07-27 11:19:00 【T_ Y_ F666】
Gauss elimination AcWing 884. Gauss elimination is used to solve XOR linear equations
Original link
AcWing 884. Gauss elimination is used to solve XOR linear equations
Algorithm tags
Linear space Gauss elimination Exclusive or
Ideas

Code
#include<bits/stdc++.h>
#define int long long
#define abs fabs
#define rep(i, a, b) for(int i=a;i<b;++i)
#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(){// Gauss elimination , The answer lies in a[i][n] in ,0 <= i < n
// c Representative column r On behalf of the line
int c, r;
// Enumerate by column
for(c=0, r=0; c<n; ++c){
int t=r;
rep(i, r, n){
if(a[i][c]){// Find non-zero line
t=i;
break;
}
}
if(!a[t][c]){
continue;
}
rep(i, c, n+1){// Change non-zero lines to the top
swap(a[r][i], a[t][i]);
}
rep(i, r+1, n){// Use non-zero rows and the following columns to eliminate as 0
if(a[i][c]){
Rep(j, n, c){
a[i][j]^=a[r][j];
}
}
}
++r;
}
if(r<n){
rep(i, r, n){
if(abs(a[i][n])>eps){
return 2;// unsolvable
}
}
return 1;// There are infinite sets of solutions
}
Rep(i, n-1, 0){
rep(j, i+1, n){
a[i][n]^=a[i][j]*a[j][n];
}
}
return 0;// There is a unique solution
}
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;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- Knapsack model acwing 423. Picking herbs
- Error: image clipToBoundsAndScale, argument 'input'
- Derive the detailed expansion of STO double center kinetic energy integral
- 01 BTC cryptology principle
- The second method of calculating overlapping integral
- Opengauss kernel analysis - statistics and row count estimation
- 高斯消元 AcWing 883. 高斯消元解线性方程组
- 树形DP AcWing 285. 没有上司的舞会
- 最长上升子序列模型 AcWing 1016. 最大上升子序列和
- Stack acwing 3302. Expression evaluation
猜你喜欢

博弈论 AcWing 893. 集合-Nim游戏

Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?

Where is the big data open source project, one-stop fully automated full life cycle operation and maintenance steward Chengying (background)?

【着色器实现Shake随机摇动效果_Shader效果第十篇】

Use of beautifulsoup

The second method of calculating overlapping integral

properties文件

博弈论 AcWing 894. 拆分-Nim游戏

Real time development platform construction practice, in-depth release of real-time data value - 04 live broadcast review

XXX packages are looking for funding run 'NPM fund' for details solutions
随机推荐
NFT leaderboard -nft real offer latest address: NFT leaderboard.com
背包模型 AcWing 1022. 宠物小精灵之收服
An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
Today's code farmer girl learned notes about event operation and ref attribute, and did the practice of form two-way binding
TensorFlow张量运算函数集
博弈论 AcWing 893. 集合-Nim游戏
Real time development platform construction practice, in-depth release of real-time data value - 04 live broadcast review
Stack acwing 3302. Expression evaluation
FAQs of "relay chain" and "dot" in Poka ecosystem
Introduction to software vulnerability analysis (I)
Learning notes uni app
Gaussian elimination acwing 883. solving linear equations with Gaussian elimination
最长上升子序列模型 AcWing 482. 合唱队形
求组合数 AcWing 887. 求组合数 III
背包模型 AcWing 423. 采药
The article will not keep VIP charges all the time. It will be open for a period of time
First experience of three.js: simulating the growth of a small branch
数字三角形模型 AcWing 1027. 方格取数
[FPGA tutorial case 40] communication case 10 -- Verilog implementation of a simple OFDM system based on FPGA
Redis+caffeine two-level cache enables smooth access speed