zoukankan      html  css  js  c++  java
  • 小z的矩阵

    传送门:https://www.luogu.org/problemnew/show/P2117

    因为矩阵中的每个元素都是0或1,那么a[i][j]*a[j][i] + a[j][i]*a[i][j]只有这样几种情况:0*1+1*0,1*0+0*1,0*0+0*0,1*1+1*1,他们%2后均为0,因此除了从左上到右下的对角线元素外,其余元素对答案的贡献均为0.

    统计对角线元素对答案的贡献,再手动举几个例子可知,每次翻转时,原来的贡献也随之翻转。

    #include<cstdio>
    using namespace std;
    inline int read()
    {
        static char ch;
        while((ch = getchar()) < '0' || ch > '9');
        int ret = ch - 48;
        while((ch = getchar()) >= '0' && ch <= '9')
            ret = ret * 10 + ch - 48;
        return ret;
     } 
    int n,q,a[10000][10000],opt,z,sum;
    int main()
    {
        n = read();
        q = read();
        for(int i = 1;i <= n;i++)
        {
            for(int j = 1;j <= n;j++)
            {
                a[i][j] = read();
                if(i == j) sum += a[i][j];
            }
        }
        sum %= 2;
        for(int i = 1;i <= q;i++)
        {
            opt = read();
            if(opt == 3)
            {
                printf("%d",sum);
            } 
            else
            {
                z = read();
                if(sum == 1) sum = 0;
                else sum = 1;
            }
        }
        return 0;
    }
  • 相关阅读:
    网页抓取
    基本数据结构
    小节
    顺序统计量
    线性时间排序
    快速排序
    堆排序 Heapsort
    大数运算
    趣味题,文本中洞的数量
    nginx config配置
  • 原文地址:https://www.cnblogs.com/peppa/p/9909667.html
Copyright © 2011-2022 走看看