题意:
中文题http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=631&pid=1002
解:
Nim博弈,不过是2维的,并且有更新操作。这里可以用二位树状数组维护。跟POJ1195很像。
#include <iostream> #include <algorithm> #include <string> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <vector> #include <queue> #define CL(arr, val) memset((arr), (val), sizeof(arr)) #define REP(i, n) for(i = 0; i < n; ++i) #define FOR(i, l, h) for(i = l; i <= h; ++i) #define FORD(i, h, l) for(i = h; i >= l; --i) #define L(x) x << 1 #define R(x) x << 1 | 1 #define MID(l, r) (l + (r - l) >> 1) using namespace std; typedef unsigned int uint; typedef long long LL; typedef unsigned long long uLL; const int N = 510; const double PI = acos(-1.0); const double eps = 1e-6; const double INF = 1e9+7; const int MOD = 1000000007; int mat[N][N]; int a[N][N]; int lowbit(int i) { return i&(-i); } void add(int x, int y, int d) { int i, j; for(i = x; i < N; i += lowbit(i)) for(j = y; j < N; j += lowbit(j)) mat[i][j] ^= d; } LL sum(int x, int y) { LL res = 0; int i, j; for(i = x; i > 0; i -= lowbit(i)) for(j = y; j > 0; j -= lowbit(j)) res ^= mat[i][j]; return res; } int main() { //freopen("data.in", "r", stdin); int T; int n, m, q; int i, j, op, ans; int x, y, x_1, y_1, z; scanf("%d", &T); while(T--) { scanf("%d%d%d", &n, &m, &q); CL(mat, 0); FOR(i, 1, n){ FOR(j, 1, m){ scanf("%d", &a[i][j]); add(i, j, a[i][j]); } } while(q--) { scanf("%d", &op); switch(op) { case 1: scanf("%d%d%d%d", &x, &y, &x_1, &y_1); x--; y--; ans = sum(x_1, y_1) ^ sum(x, y_1) ^ sum(x_1, y) ^ sum(x, y); //这里需要注意 if(ans != 0) puts("Yes"); else puts("No"); break; case 2: scanf("%d%d%d", &x, &y, &z); if(z == a[x][y]) continue; add(x, y, a[x][y]); add(x, y, z); a[x][y] = z; break; default: break; } } } return 0; }
i,j。