zoukankan      html  css  js  c++  java
  • 河南理工大学新生挑战赛(重现赛)D LaunchPad (模拟优化)

    题目链接:https://ac.nowcoder.com/acm/contest/3665/D

      题意就是给你一个n*m的矩阵,然后一开始矩阵都是0,每次让矩阵的一行与一列取反,问q次操作后矩阵每个点状态是1的

    数目有多少。

      如果直接模拟的话时间会超时,所以可以用两个数组分别记录行、列的变化,但是只是这样的话行与列的交叉点的变化就不好

    表示了,所以再用一个二维数组来表示单个点的变化

      

    #include<set>
    #include<map>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<cstdio>
    #include<cctype>
    #include<string>
    #include<vector>
    #include<climits>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    #include<unordered_map>
    #define endl '\n'
    #define max(a, b) (a > b ? a : b)
    #define min(a, b) (a < b ? a : b)
    #define mst(a) memset(a, 0, sizeof(a))
    #define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> P;
    const double pi = acos(-1.0);
    const double eps = 1e-7;
    const int INF = 0x3f3f3f3f;
    const int _NAN = -0x3f3f3f3f;
    const int NIL = -1;
    const int maxn = 1e3+10;
    int matrix[maxn][maxn], h[maxn], l[maxn];
    int main(void){
        int n, m, q;
        while(~scanf("%d%d", &n, &m)) {
            scanf("%d", &q);
            while(q--) {
                int x, y;
                scanf("%d%d", &x, &y);
                matrix[x][y] ^= 1;
                h[x] ^= 1;
                l[y] ^= 1;
            }
            int sum = 0;
            for (int i = 1; i<=n; ++i)
                for (int j = 1; j<=m; ++j)
                    sum += h[i]^l[j]^matrix[i][j];
            printf("%d\n", sum);
            mst(matrix);
            mst(h);
            mst(l);
        }
        return 0;
    }
  • 相关阅读:
    Spring IOC、AOP实现源码分析
    mybatis源码分析
    Android 屏幕适配
    读取sd卡下图片,由图片路径转换为bitmap
    SVN的trunk、branch、tag(二)
    SVN中tag branch trunk用法详解
    SVN使用教程之——分支、合并
    svn回滚版本2
    svn回滚版本1
    TortoiseSVN中分支和合并实践
  • 原文地址:https://www.cnblogs.com/shuitiangong/p/12257455.html
Copyright © 2011-2022 走看看