2020ICPC济南站 A . Matrix Equation (高斯消元)

简介: 2020ICPC济南站 A . Matrix Equation (高斯消元)

linkkk

题意:

20200401134307494.png

思路:

A×C=BC

k=1nAi,kCk,j=Bi,jCi,j

对于1 < = j < = n

(A1,1C1,j+A1,2C2,j++A1,nCn,j)%2=B1,jC1,j

01的加法和取余2 22相当于异或。

式子变成了

(A1,1C1,jA1,2C2,jA1,nCn,j)=B1,jC1,j

相当于解一个异或线性方程组,对于1 < = j < = n 中,是相互独立的。最后2 总 自 由 元 个 数 2^{总自由元个数}2

总自由元个数

就是答案。

如果A 1 , 1 = B 1 , j则a 1 , 1 = 0,这样右侧的结果位都是0;A1,1!=B1,j,则a 1 , 1 = 1

代码:

// Problem: Matrix Equation
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/10662/A
// Memory Limit: 524288 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PLL;
typedef pair<int, int>PII;
typedef pair<double, double>PDD;
typedef pair<string,string>PSS;
#define I_int ll
inline ll read(){ll x = 0, f = 1;char ch = getchar();while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}return x * f;}
inline void write(ll x){if (x < 0) x = ~x + 1, putchar('-');if (x > 9) write(x / 10);putchar(x % 10 + '0');}
#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
ll ksm(ll a, ll b,ll mod){ll res = 1;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
const int maxn=2010;
const double pi = acos(-1);
ll n,m=31;
ll a[210][210],g[210];
int A[210][210],B[210][210];
const int mod=998244353;
int Gauss(int n,int m)
{
    int r, c;
    for(r = 0, c = 0; c < n; c++)
    {
        int t = -1;
        for(int i = r; i < m; i++)
        {
            if(a[i][c])
            {
                t = i;
                break;
            }
        }
        if(t==-1) continue;
        for(int i = c; i < n; i++)///交换
        {
            swap(a[t][i], a[r][i]);
        }
        for(int i = r + 1; i < m; i++)
        {
            if(a[i][c])
                for(int j = c; j <n; j++)
                {
                    a[i][j] =  a[i][j] ^ a[r][j];
                }
        }
        r++;
    }
  return n-r;
}
void solve()
{
    n=read;
    for(int i=0;i<n;i++) 
      for(int j=0;j<n;j++)
        A[i][j]=read;
  for(int i=0;i<n;i++) 
      for(int j=0;j<n;j++)
      B[i][j]=read;
    ll cnt=0;
    for(int j=0;j<n;j++){
      for(int i=0;i<n;i++){
        for(int k=0;k<n;k++){
          a[i][k]=A[i][k];
        }
        a[i][n]=0;
        if(A[i][i]==B[i][j]) a[i][i]=0;
        else a[i][i]=1;
      }
      ll tot=Gauss(n,n);
      if(tot<0){
        puts("0");
        return ;
      }
    else{
      cnt+=tot;
    }
    }
    cout<<ksm(2,cnt,mod)<<endl;
}
int main()
{
    int _;_=1;
    while(_--) solve();
    return 0;
}
目录
相关文章
|
11月前
2021山东省赛 M . Matrix Problem(构造)
2021山东省赛 M . Matrix Problem(构造)
40 0
|
12月前
|
机器学习/深度学习 C++
【PAT甲级 - C++题解】1105 Spiral Matrix
【PAT甲级 - C++题解】1105 Spiral Matrix
52 0
|
12月前
|
机器学习/深度学习 C++
【PAT甲级 - C++题解】1059 Prime Factors
【PAT甲级 - C++题解】1059 Prime Factors
61 0
|
并行计算
2019年第10届山东省赛 L . Median (floyd 拓扑排序)
2019年第10届山东省赛 L . Median (floyd 拓扑排序)
77 0
|
定位技术 容器
PTA天梯训练赛一&二
PTA天梯训练赛一&二
89 0
|
机器学习/深度学习
2019CCPC厦门站 H. Zayin and Obstacles(三维前缀和 bfs)
2019CCPC厦门站 H. Zayin and Obstacles(三维前缀和 bfs)
63 0
UPC组队赛第三场——G: The Famous ICPC Team Again (主席树)
UPC组队赛第三场——G: The Famous ICPC Team Again (主席树)
75 0
|
机器学习/深度学习
[Nowcoder | UPC] 2021年度训练联盟热身训练赛第六场 Hopscotch | 最短路 bfs
题目描述 There’s a new art installation in town, and it inspires you… to play a childish game. The art installation consists of a floor with an n×n matrix of square tiles. Each tile holds a single number from 1 to k. You want to play hopscotch on it.
99 0

热门文章

最新文章