当前位置:网站首页>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;
}
边栏推荐
- RDF query language SPARQL
- CF1638E. Colorful operations Kodori tree + differential tree array
- [daily question in summer] function of rogu p3742 UMI
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
- 【FTP】FTP常用命令,持续更新中……
- 【暑期每日一题】洛谷 P7222 [RC-04] 信息学竞赛
- Shell之Unix运维常用命令
- Pytest automated testing - compare robotframework framework
- Basic skeleton of neural network nn Use of moudle
- STM32扩展板 数码管显示
猜你喜欢

C#读写应用程序配置文件App.exe.config,并在界面上显示

分布式-总结列表

Technology sharing | broadcast function design in integrated dispatching

Use of dataloader

Pytoch (II) -- activation function, loss function and its gradient

Cmake selecting compilers and setting compiler options
![[summer daily question] Luogu p5886 Hello, 2020!](/img/ac/4be05f80aab7fb766674e6e2d16fbc.png)
[summer daily question] Luogu p5886 Hello, 2020!

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

C -- array
![Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*](/img/88/0b99d1db2cdc70ab72d2b3c623dfaa.jpg)
Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*
随机推荐
Leecode record 1351 negative numbers in statistical ordered matrix
Neural networks - use of maximum pooling
Dataloader的使用
LeetCode_28(实现 strStr())
Fitness without equipment
[daily question in summer] Luogu p7222 [rc-04] informatics competition
FileOutPutStream
Buffer stream and transform stream
Pytoch (III) -- function optimization
Shell之一键自动部署Redis任意版本
Neural networks - use sequential to build neural networks
AssertionError assert I.ndim == 4 and I.shape[1] == 3
[FTP] the solution to "227 entering passive mode" during FTP connection
Pytoch (I) -- basic grammar
【暑期每日一题】洛谷 P2026 求一次函数解析式
C -- array
Construction of Meizhou nursing laboratory: equipment configuration
Solution: thread 1:[< *> setvalue:forundefined key]: this class is not key value coding compliant for the key*
C - detailed explanation of operators and summary of use cases
Kodori tree board