当前位置:网站首页>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;
}
边栏推荐
- LeetCode_28(实现 strStr())
- 神经网络-非线性激活
- FileOutPutStream
- Pico Neo3手柄抓取物体
- 分布式数据库数据一致性的原理、与技术实现方案
- How to do the performance pressure test of "Health Code"
- Oracle views the creation time of the tablespace in the database
- Leecode question brushing record 1332 delete palindrome subsequence
- 【硬十宝典目录】——转载自“硬件十万个为什么”(持续更新中~~)
- Overview of the construction details of Meizhou veterinary laboratory
猜你喜欢

STM32扩展版 按键扫描

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

Manually implement a simple stack

Common methods in transforms

RuntimeError: “max_pool2d“ not implemented for ‘Long‘

解决:拖动xib控件到代码文件中,报错setValue:forUndefinedKey:this class is not key value coding-compliant for the key

This sideline workload is small, 10-15k, free unlimited massage

pytorch中常用数据集的使用方法

STM32 extended key scan

Distributed - summary list
随机推荐
VIM简易使用教程
Openresty rewrites the location of 302
【暑期每日一题】洛谷 P5740【深基7.例9】最厉害的学生
C#读写应用程序配置文件App.exe.config,并在界面上显示
C read / write application configuration file app exe. Config and display it on the interface
【暑期每日一題】洛穀 P1568 賽跑
js解决浮点数相乘精度丢失问题
无器械健身
神经网络的基本骨架-nn.Moudle的使用
[daily question in summer] Luogu p1568 race
Solve the problem that the external chain file of Qiankun sub application cannot be obtained
Neural networks - use sequential to build neural networks
[une question par jour pendant l'été] course luogu p1568
Neural network convolution layer
Shell之Unix运维常用命令
JS to solve the problem of floating point multiplication precision loss
Matters behind the construction of paint testing laboratory
Why is Internet thinking not suitable for AI products?
Talk about testdeploy
解决qiankun中子应用外链文件无法获取