当前位置:网站首页>AcWing 884. Gauss elimination for solving XOR linear equations
AcWing 884. Gauss elimination for solving XOR linear equations
2022-07-01 04:51:00 【MangataTS】
Topic linking
https://www.acwing.com/problem/content/886/
Ideas
Similar to floating-point Gauss elimination , The steps are the same , But the operation here has become XOR , For the r That's ok , The first c We hope to add the following [r+1,n) OK, No c All the bits are set as 0, In fact, this is no different from ordinary Gauss elimination
Code
#include<bits/stdc++.h>
using namespace std;
//---------------- Custom part ----------------
#define ll long long
#define mod 1000000007
#define endl "\n"
#define PII pair<int,int>
#define INF 0x3f3f3f3f
int dx[4] = {
-1, 0, 1, 0}, dy[4] = {
0, 1, 0, -1};
ll ksm(ll a,ll b) {
ll ans = 1;
for(;b;b>>=1LL) {
if(b & 1) ans = ans * a % mod;
a = a * a % mod;
}
return ans;
}
ll lowbit(ll x){
return -x & x;}
const int N = 1e2+10;
//---------------- Custom part ----------------
int t,n,m,q,a[N][N];
int guss(){
int c,r;
for(c=0,r=0;c <= n; ++c){
int t = r;
for(int i = r;i < n; ++i){
// Find one not for 0 The line of
if(a[i][c]) {
t = i;
break;
}
}
if(!a[t][c]) continue;
for(int i = 0;i <= n; ++i) swap(a[t][i],a[r][i]);
for(int i = r + 1;i < n; ++i) {
// Elimination
if(a[i][c])
for(int j = c;j <= n; ++j)
a[i][j] ^= a[r][j];
}
r++;
}
if(r < n){
for(int i = r;i < n; ++i)
if(a[i][n]) return 1;
return 2;
}
for(int i = n-1;i >= 0; --i) {
for(int j = i + 1;j < n; ++j) {
a[i][n] ^= a[i][j] * a[j][n];
}
}
return 0;
}
void slove(){
cin>>n;
for(int i = 0;i < n; ++i)
for(int j = 0;j <= n; ++j)
cin>>a[i][j];
int t = guss();
if(t == 1) puts("No solution");
else if(t == 2) puts("Multiple sets of solutions");
else {
for(int i = 0;i < n; ++i) cout<<a[i][n]<<endl;
}
}
int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
t = 1;
while(t--){
slove();
}
return 0;
}
边栏推荐
- LeetCode522-最长特殊序列II-哈希表-字符串-双指针
- Common interview questions ①
- Pytoch (III) -- function optimization
- Codeworks round 449 (Div. 1) C. Kodori tree template
- 【暑期每日一题】洛谷 P5886 Hello, 2020!
- 手动实现一个简单的栈
- 对象的序列化与反序列化
- Fitness without equipment
- Pytest automated testing - compare robotframework framework
- This sideline workload is small, 10-15k, free unlimited massage
猜你喜欢

Difficulties in the development of knowledge map & the importance of building industry knowledge map

How to do the performance pressure test of "Health Code"

One click shell to automatically deploy any version of redis

STM32扩展板 数码管显示

Basic usage, principle and details of session
![[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply](/img/c2/6dfb9f477306edb46ff2a6a6ca32dd.png)
[hard ten treasures] - 2 [basic knowledge] characteristics of various topological structures of switching power supply

Neural network - nonlinear activation

Pytoch (I) -- basic grammar

Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom

技术分享| 融合调度中的广播功能设计
随机推荐
分布式-总结列表
js解决浮点数相乘精度丢失问题
One click shell to automatically deploy any version of redis
【暑期每日一题】洛谷 P2637 第一次,第二次,成交!
Pytorch(四) —— 可视化工具 Visdom
C - detailed explanation of operators and summary of use cases
VIM easy to use tutorial
线程类的几大创建方法
1076 Forwards on Weibo
Pico neo3 handle grabs objects
Shell之分析服务器日志命令集锦
Difficulties in the development of knowledge map & the importance of building industry knowledge map
LeetCode316-去除重复字母-栈-贪心-字符串
解决qiankun中子应用外链文件无法获取
数据加载及预处理
Sorting out 49 reports of knowledge map industry conference | AI sees the future with wisdom
Construction of Meizhou nursing laboratory: equipment configuration
Leecode record 1351 negative numbers in statistical ordered matrix
Leecode records the number of good segmentation of 1525 strings
AssertionError assert I.ndim == 4 and I.shape[1] == 3