当前位置:网站首页>高斯消元 AcWing 884. 高斯消元解异或线性方程组
高斯消元 AcWing 884. 高斯消元解异或线性方程组
2022-07-05 06:16: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;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 做 SQL 性能优化真是让人干瞪眼
- The sum of the unique elements of the daily question
- MySQL advanced part 2: SQL optimization
- Overview of variable resistors - structure, operation and different applications
- 1.13 - RISC/CISC
- Navicat连接Oracle数据库报错ORA-28547或ORA-03135
- Matrixdb V4.5.0 was launched with a new mars2 storage engine!
- liunx启动redis
- 2021apmcm post game Summary - edge detection
- 1040 Longest Symmetric String
猜你喜欢

Overview of variable resistors - structure, operation and different applications

1.15 - input and output system

开源存储这么香,为何我们还要坚持自研?

Appium automation test foundation - Summary of appium test environment construction
![R language [import and export of dataset]](/img/5e/a15ab692a6f049f846024c98820fbb.png)
R language [import and export of dataset]

Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition

SQLMAP使用教程(一)

阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长

MySQL advanced part 1: index
![Introduction to LVS [unfinished (semi-finished products)]](/img/72/d5a943a8d6d71823dcbd7f23dda35b.png)
Introduction to LVS [unfinished (semi-finished products)]
随机推荐
多屏电脑截屏会把多屏连着截下来,而不是只截当前屏
Leetcode stack related
[rust notes] 16 input and output (Part 2)
Leetcode recursion
Leetcode heap correlation
leetcode-6110:网格图中递增路径的数目
Leetcode array operation
LeetCode 0107.二叉树的层序遍历II - 另一种方法
Regulations for network security events of vocational group in 2022 Guizhou Vocational College skill competition
Traversal of leetcode tree
Daily question 1189 Maximum number of "balloons"
Usage scenarios of golang context
MySQL advanced part 1: index
Leetcode-9: palindromes
SQLMAP使用教程(一)
927. 三等分 模拟
[rust notes] 17 concurrent (Part 2)
LVS简介【暂未完成(半成品)】
SPI details
Groupbykey() and reducebykey() and combinebykey() in spark