hdu 5465 Clarke and puzzle(前缀和,异或,nim博弈)
2015-09-22 20:07
295 查看
[align=left]Problem Description[/align]
[align=left]Input[/align]
[align=left]Output[/align]
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
Hint:
The first enquiry: $a$ can decrease grid $(1, 2)$'s number by $1$. No matter what $b$ operate next, there is always one grid with number $1$ remaining . So, $a$ wins.
The second enquiry: No matter what $a$ operate, there is always one grid with number $1$ remaining. So, $b$ wins.
[align=left]Source[/align]
BestCoder Round #56 (div.2)
题目要求二维的nim游戏,考虑到nim的结论是xor和为0则必败、否则必胜,那么我们只需要维护子矩阵的xor和。由于xor有前缀和性质,所以我们可以用一个二维bit来维护(1, 1)-(a, b)的矩阵的xor和,然后由sum(x2,y2) xor sum(x2,y1−1) xor sum(x1−1,y2) xor sum(x1−1,y1−1)sum(x2, y2) \ xor \ sum(x2, y1-1) \ xor \ sum(x1-1, y2) \ xor \ sum(x1-1, y1-1)sum(x2,y2) xor sum(x2,y1−1) xor sum(x1−1,y2) xor sum(x1−1,y1−1)来得到答案即可。单点修改在bit上是很容易的。
View Code
Clarke is a patient with multiple personality disorder. One day, Clarke split into two personality a and b, they are playing a game. There is a n∗m matrix, each grid of this matrix has a number ci,j. a wants to beat b every time, so a ask you for a help. There are q operations, each of them is belonging to one of the following two types: 1. They play the game on a (x1,y1)−(x2,y2) sub matrix. They take turns operating. On any turn, the player can choose a grid which has a positive integer from the sub matrix and decrease it by a positive integer which less than or equal this grid's number. The player who can't operate is loser. a always operate first, he wants to know if he can win this game. 2. Change ci,j to b.
[align=left]Input[/align]
The first line contains a integer T(1≤T≤5), the number of test cases. For each test case: The first line contains three integers n,m,q(1≤n,m≤500,1≤q≤2∗105) Then n∗m matrix follow, the i row j column is a integer ci,j(0≤ci,j≤109) Then q lines follow, the first number is opt. if opt=1, then 4 integers x1,y1,x1,y2(1≤x1≤x2≤n,1≤y1≤y2≤m) follow, represent operation 1. if opt=2, then 3 integers i,j,b follow, represent operation 2.
[align=left]Output[/align]
For each testcase, for each operation 1, print Yes if a can win this game, otherwise print No.
[align=left]Sample Input[/align]
1 1 2 3 1 2 1 1 1 1 2 2 1 2 1 1 1 1 1 2
[align=left]Sample Output[/align]
Yes No
Hint:
The first enquiry: $a$ can decrease grid $(1, 2)$'s number by $1$. No matter what $b$ operate next, there is always one grid with number $1$ remaining . So, $a$ wins.
The second enquiry: No matter what $a$ operate, there is always one grid with number $1$ remaining. So, $b$ wins.
[align=left]Source[/align]
BestCoder Round #56 (div.2)
题目要求二维的nim游戏,考虑到nim的结论是xor和为0则必败、否则必胜,那么我们只需要维护子矩阵的xor和。由于xor有前缀和性质,所以我们可以用一个二维bit来维护(1, 1)-(a, b)的矩阵的xor和,然后由sum(x2,y2) xor sum(x2,y1−1) xor sum(x1−1,y2) xor sum(x1−1,y1−1)sum(x2, y2) \ xor \ sum(x2, y1-1) \ xor \ sum(x1-1, y2) \ xor \ sum(x1-1, y1-1)sum(x2,y2) xor sum(x2,y1−1) xor sum(x1−1,y2) xor sum(x1−1,y1−1)来得到答案即可。单点修改在bit上是很容易的。
#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<math.h> #include<algorithm> #include<queue> #include<set> #include<bitset> #include<map> #include<vector> #include<stdlib.h> #include <stack> using namespace std; int dirx[]={0,0,-1,1}; int diry[]={-1,1,0,0}; #define PI acos(-1.0) #define max(a,b) (a) > (b) ? (a) : (b) #define min(a,b) (a) < (b) ? (a) : (b) #define ll long long #define eps 1e-10 #define MOD 1000000007 #define N 506 #define inf 1e12 int n,m,q; int mp ; int a ; int main() { int t; scanf("%d",&t); while(t--){ scanf("%d%d%d",&n,&m,&q); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&mp[i][j]); a[i][j]=a[i][j-1]^mp[i][j]; } } for(int i=0;i<q;i++){ int opt; scanf("%d",&opt); int x,y,z; if(opt==2){ scanf("%d%d%d",&x,&y,&z); mp[x][y]=z; for(int j=y;j<=m;j++){ a[x][j]=a[x][j-1]^mp[x][j]; } } else{ int ans=0; int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); for(int j=x1;j<=x2;j++){ ans=ans^(a[j][y2]^a[j][y1-1]); } if(ans==0){ printf("No\n"); } else{ printf("Yes\n"); } } } } return 0; }
View Code
相关文章推荐
- Android读写操作之sdcard的读写操作
- Jesus Is Here(区域赛网络赛选拔)
- LeetCode(81) Search in Rotated Array II
- codeforces 578 B. Finding Team Member( Codeforces Round #320 (Div. 2) )
- LeetCode(81) Search in Rotated Array II
- ORA-12520与ORA-12514(监听相关问题)
- [MFC]CDocument文档类简介
- iOS开发 ----- APPDelegate回调
- iOS开发 ----- 网络请求
- Codeforces Round #104 (Div. 2) ABCD
- JAVA上机——
- 编译android内核和文件系统,已经安装jdk,提示build/core/config.mk:268: *** Error: could not find jdk tools.jar
- iOS开发 ---- 其他控件,弹窗,滑块,菊花,步进,分段等
- Codeforces 461B Appleman and Tree(木dp)
- JavaScript学习总结(一)基础部分
- C++多线程编程
- iOS开发 ----- UISearchBar_UISearchController
- 社团划分——Fast Unfolding算法
- Android开发之闹钟
- JAVA Current date and time