当前位置:网站首页>高斯消元 AcWing 884. 高斯消元解异或線性方程組
高斯消元 AcWing 884. 高斯消元解异或線性方程組
2022-07-05 06:18:00 【T_Y_F666】
高斯消元 AcWing 884. 高斯消元解异或線性方程組
原題鏈接
算法標簽
線性空間 高斯消元 异或
思路

代碼
#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(){// 高斯消元,答案存於a[i][n]中,0 <= i < n
// c代錶列 r代錶行
int c, r;
// 按列枚舉
for(c=0, r=0; c<n; ++c){
int t=r;
rep(i, r, n){
if(a[i][c]){// 找非零行
t=i;
break;
}
}
if(!a[t][c]){
continue;
}
rep(i, c, n+1){// 將非零行換到最頂端
swap(a[r][i], a[t][i]);
}
rep(i, r+1, n){// 用非零行與下面列進行運算消除為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;// 無解
}
}
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;
}
原創不易
轉載請標明出處
如果對你有所幫助 別忘啦點贊支持哈
边栏推荐
- Operator priority, one catch, no doubt
- The difference between CPU core and logical processor
- LeetCode-54
- Single chip computer engineering experience - layered idea
- Real time clock (RTC)
- liunx启动redis
- MatrixDB v4.5.0 重磅发布,全新推出 MARS2 存储引擎!
- Sum of three terms (construction)
- Sword finger offer II 058: schedule
- 【LeetCode】Easy | 20. Valid parentheses
猜你喜欢

数据可视化图表总结(二)

Leetcode array operation

栈 AcWing 3302. 表达式求值

leetcode-6111:螺旋矩阵 IV

传统数据库逐渐“难适应”,云原生数据库脱颖而出

redis发布订阅命令行实现
![[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian](/img/f1/e7a8a1a31bc5712d9f32d91305a2b0.jpg)
[2021]IBRNet: Learning Multi-View Image-Based Rendering Qianqian

Data visualization chart summary (I)

LeetCode 0108. Convert an ordered array into a binary search tree - the median of the array is the root, and the left and right of the median are the left and right subtrees respectively

MIT-6874-Deep Learning in the Life Sciences Week 7
随机推荐
[rust notes] 14 set (Part 2)
LeetCode 1200. Minimum absolute difference
[rust notes] 13 iterator (Part 2)
【Rust 笔记】13-迭代器(下)
1040 Longest Symmetric String
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
Liunx starts redis
Quickly use Amazon memorydb and build your own redis memory database
Leetcode-6109: number of people who know secrets
LeetCode 0108.将有序数组转换为二叉搜索树 - 数组中值为根,中值左右分别为左右子树
Règlement sur la sécurité des réseaux dans les écoles professionnelles secondaires du concours de compétences des écoles professionnelles de la province de Guizhou en 2022
Sqlmap tutorial (II) practical skills I
Leetcode-3: Longest substring without repeated characters
[rust notes] 14 set (Part 1)
4. Object mapping Mapster
Leetcode backtracking method
【Rust 笔记】17-并发(下)
Currently clicked button and current mouse coordinates in QT judgment interface
LeetCode-54