Clarke and puzzle

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 951    Accepted Submission(s): 349

Problem Description
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.

 
Input
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.
 
Output
For each testcase, for each operation 1, print Yes if a can win this game, otherwise print No.
 
Sample Input
1
1 2 3
1 2
1 1 1 1 2
2 1 2 1
1 1 1 1 2
 
Sample Output
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.

 
Source
 
    对于操作1而言就是一个裸的nim博弈,答案就是 {c[x1][y1]^......^c[x2][y2]}
   操作二就是改变了格子中的一个数。
        用二维BIT来维护矩阵内的异或和即可。
 
  (最近总把下标写错,,把x1,y1写成了i,j检查半天, (误

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ULL unsigned long long
  4. #define LL long long
  5. int c[][];
  6. int C[][];
  7. int N,M;
  8. inline int lowbit(int x){return x&-x;}
  9. void change(int x,int y,int d){
  10. for(int i=x;i<=N;i+=lowbit(i))
  11. for(int j=y;j<=M;j+=lowbit(j))
  12. C[i][j]^=d;
  13. }
  14. int ask(int x,int y){
  15. int r=;
  16. for(int i=x;i;i-=lowbit(i))
  17. for(int j=y;j;j-=lowbit(j))
  18. r^=C[i][j];
  19. return r;
  20. }
  21. int main(){
  22. int t,n,m,i,q,j,k,x1,x2,y1,y2;
  23. scanf("%d",&t);
  24. while(t--){
  25. memset(C,,sizeof(C));
  26. scanf("%d%d%d",&n,&m,&q);
  27. N=n,M=m;
  28. for(i=;i<=n;++i){
  29. for(j=;j<=m;++j){
  30. scanf("%d",&c[i][j]);
  31. change(i,j,c[i][j]);
  32. }
  33. }
  34.  
  35. int opt,d;
  36. while(q--){
  37. scanf("%d",&opt);
  38. if(opt==){
  39. scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
  40. int ans=(ask(x2,y2)^ask(x1-,y1-)^ask(x1-,y2)^ask(x2,y1-));
  41. ans?puts("Yes"):puts("No");
  42. }
  43. else{
  44. scanf("%d%d%d",&x1,&y1,&d);
  45. change(x1,y1,(d^c[x1][y1]));
  46. c[x1][y1]=d;
  47. }
  48. }
  49. }
  50. return ;
  51. }

hdu-5465-二维BIT+nim的更多相关文章

  1. HDU 5465 Clarke and puzzle Nim游戏+二维树状数组

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle  Accepts: 42  Submissions: 26 ...

  2. HDU 2159 二维费用背包问题

    一个关于打怪升级的算法问题.. 题意:一个人在玩游戏老是要打怪升级,他愤怒了,现在,还差n经验升级,还有m的耐心度(为零就删游戏不玩了..),有m种怪,有一个最大的杀怪数s(杀超过m只也会删游戏的.. ...

  3. hdu 4819 二维线段树模板

    /* HDU 4819 Mosaic 题意:查询某个矩形内的最大最小值, 修改矩形内某点的值为该矩形(Mi+MA)/2; 二维线段树模板: 区间最值,单点更新. */ #include<bits ...

  4. F - F HDU - 1173(二维化一维-思维)

    F - F HDU - 1173 一个邮递员每次只能从邮局拿走一封信送信.在一个二维的直角坐标系中,邮递员只能朝四个方向移动,正北.正东.正南.正西. 有n个需要收信的地址,现在需要你帮助找到一个地方 ...

  5. HDU 3496 (二维费用的01背包) Watch The Movie

    多多想看N个动画片,她对这些动画片有不同喜欢程度,而且播放时长也不同 她的舅舅只能给她买其中M个(不多不少恰好M个),问在限定时间内观看动画片,她能得到的最大价值是多少 如果她不能在限定时间内看完买回 ...

  6. hdu 2642 二维树状数组 单点更新区间查询 模板水题

    Stars Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/65536 K (Java/Others) Total Subm ...

  7. hdu 2888 二维RMQ模板题

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. Coconuts HDU - 5925 二维离散化 自闭了

    TanBig, a friend of Mr. Frog, likes eating very much, so he always has dreams about eating. One day, ...

  9. HDU 1263 二维map

    题意:给出一份水果的交易表,根据地区统计出水果的交易情况.   思路:二维map使用.   #include<cstdio> #include<string> #include ...

  10. hdu 2888 二维RMQ

    Check Corners Time Limit: 2000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. web前端----jQuery事件

    事件 常用事件 click(function(){...}) hover(function(){...}) blur(function(){...}) focus(function(){...}) c ...

  2. web前端----JavaScript的DOM(一)

    一.什么是HTML  DOM HTML  Document Object Model(文档对象模型) HTML DOM 定义了访问和操作HTML文档的标准方法 HTML DOM 把 HTML 文档呈现 ...

  3. (iOS)关于键盘遮挡textfield问题

    记录一下自己经常遇到问题.使用textfield(textview).当输入框位置比较靠下时,弹出的键盘会遮挡输入框,这是就需要动态移动输入框编辑状态时self.view的位置, 自己经常用的方法有两 ...

  4. 原生JS操作AJAX

    1,get方式的AJAX function sendAjaxReq() { //1,创建ajax引擎 XMLHttpRequest对象 var req = new XMLHttpRequest() | ...

  5. Removing bad blocks from the USB drive with fsck

    An easy way to repair a flash drive, or any drive really, is to use the fsck tool. This tool is grea ...

  6. Linux多线程--使用信号量同步线程【转】

    本文转载自:http://blog.csdn.net/ljianhui/article/details/10813469 信号量.同步这些名词在进程间通信时就已经说过,在这里它们的意思是相同的,只不过 ...

  7. spring boot 使用@ConfigurationProperties

    有时候有这样子的情景,我们想把配置文件的信息,读取并自动封装成实体类,这样子,我们在代码里面使用就轻松方便多了,这时候,我们就可以使用@ConfigurationProperties,它可以把同类的配 ...

  8. 【镜像地址】Maven地址列表

    1.国内OSChina提供的镜像,非常不错 <mirror> <id>CN</id> <name>OSChina Central</name> ...

  9. IDEA快捷键复习使用

    https://www.jetbrains.com/help/idea/meet-intellij-idea.html 快捷键可以极快地进行代码编辑整理,在IDEA的快捷键中,除了有几个好像特别难按之 ...

  10. 到底二级域名和一级域名哪个更利于SEO

    到底二级域名和一级域名哪个更利于SEO呢?本文是从百度官方转载详细的介绍:二级域名和一级域名的区别,请各位认真阅读. 二级域名和子域名的区别可以通过以下3点来解读: 一,二级域名的特点 搜索引擎往往将 ...