当前位置:网站首页>Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
Gaussian elimination acwing 884 Gauss elimination for solving XOR linear equations
2022-07-05 06:18: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
边栏推荐
- Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
- LeetCode 1200.最小绝对差
- 【Rust 笔记】16-输入与输出(下)
- SQLMAP使用教程(一)
- SQLMAP使用教程(二)实战技巧一
- Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
- js快速将json数据转换为url参数
- [2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
- Appium foundation - use the first demo of appium
- 什么是套接字?Socket基本介绍
猜你喜欢
【LeetCode】Easy | 20. Valid parentheses
MySQL advanced part 1: View
Overview of variable resistors - structure, operation and different applications
LeetCode 0107. Sequence traversal of binary tree II - another method
Leetcode stack related
SQL三种连接:内连接、外连接、交叉连接
博弈论 AcWing 894. 拆分-Nim游戏
做 SQL 性能优化真是让人干瞪眼
Single chip computer engineering experience - layered idea
SPI 详解
随机推荐
11-gorm-v2-03-basic query
[rust notes] 14 set (Part 1)
C - XOR to all (binary topic)
数据可视化图表总结(一)
MySQL advanced part 1: triggers
Redis publish subscribe command line implementation
leetcode-3:无重复字符的最长子串
TypeScript 基础讲解
做 SQL 性能优化真是让人干瞪眼
1.15 - input and output system
Chart. JS - Format Y axis - chart js - Formatting Y axis
__ builtin_ Popcount() counts the number of 1s, which are commonly used in bit operations
In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}
C Primer Plus Chapter 15 (bit operation)
剑指 Offer II 058:日程表
Golang uses context gracefully
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
博弈论 AcWing 891. Nim游戏
【Rust 笔记】14-集合(下)
Doing SQL performance optimization is really eye-catching