标签:test name end tor typedef pac stream str href
题目链接: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; }
河南理工大学新生挑战赛(重现赛)D - LaunchPad (模拟优化)
标签:test name end tor typedef pac stream str href
原文地址:https://www.cnblogs.com/shuitiangong/p/12257455.html