hdu 5465 Clarke and puzzle(前缀和,异或,nim博弈)
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:
. 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.
. Change ci,j to b.
The first line contains a integer T(≤T≤), the number of test cases.
For each test case:
The first line contains three integers n,m,q(≤n,m≤,≤q≤∗)
Then n∗m matrix follow, the i row j column is a integer ci,j(≤ci,j≤)
Then q lines follow, the first number is opt.
if opt=, then integers x1,y1,x1,y2(≤x1≤x2≤n,≤y1≤y2≤m) follow, represent operation .
if opt=, then integers i,j,b follow, represent operation .
For each testcase, for each operation , print Yes if a can win this game, otherwise print No.
Yes
No
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.
题目要求二维的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[]={,,-,};
int diry[]={-,,,};
#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[N][N];
int a[N][N];
int main()
{
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&mp[i][j]);
a[i][j]=a[i][j-]^mp[i][j];
}
}
for(int i=;i<q;i++){
int opt;
scanf("%d",&opt);
int x,y,z;
if(opt==){
scanf("%d%d%d",&x,&y,&z);
mp[x][y]=z;
for(int j=y;j<=m;j++){
a[x][j]=a[x][j-]^mp[x][j];
}
}
else{
int ans=;
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-]);
}
if(ans==){
printf("No\n");
}
else{
printf("Yes\n");
}
}
}
}
return ;
}
hdu 5465 Clarke and puzzle(前缀和,异或,nim博弈)的更多相关文章
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- HDU 5465——Clarke and puzzle——————【树状数组BIT维护前缀和+Nim博弈】
Clarke and puzzle Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- BestCoder Round #56 1002 Clarke and problem 1003 Clarke and puzzle (dp,二维bit或线段树)
今天第二次做BC,不习惯hdu的oj,CE过2次... 1002 Clarke and problem 和Codeforces Round #319 (Div. 2) B Modulo Sum思路差不 ...
- 2015北京网络赛 J Clarke and puzzle 求五维偏序 分块+bitset
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/contest/acmicpc20 ...
- HDU 5628 Clarke and math——卷积,dp,组合
HDU 5628 Clarke and math 本文属于一个总结了一堆做法的玩意...... 题目 简单的一个式子:给定$n,k,f(i)$,求 然后数据范围不重要,重要的是如何优化这个做法. 这个 ...
- hdu 1730 Nim博弈
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1730 Nim博弈为:n堆石子,每个人可以在任意一堆中取任意数量的石子 n个数异或值为0就后手赢,否则先 ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
随机推荐
- pyqt 动态显示时间方法例子学习
# -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' import sys,datetime from PyQt4.QtC ...
- JSON 学习笔记
学习使用json过程随笔: json数组格式 var employees = [ { "firstName":"Bill" , "lastName&q ...
- js中退出语句break,continue和return 比较(转)
原链接:http://blog.163.com/ued_er/blog/static/199703159201210283107315/ js中退出语句break,continue和return 比较 ...
- 前端--关于javascript对象
在javascript中对象是一种基本的数据类型,在数据结构上是一种散列表,可以看作是属性的无序集合,除了原始值其他一切都是对象.它可以用来表示现实世界中或者我们大脑中抽象出来的客体,这和其他面向对象 ...
- Asp.net Mvc 请求是如何到达 MvcHandler的——UrlRoutingModule、MvcRouteHandler分析,并造个轮子
这个是转载自:http://www.cnblogs.com/keyindex/archive/2012/08/11/2634005.html(那个比较容易忘记,希望博主不要生气的) 前言 本文假定读者 ...
- C# 4.0 并行计算部分
C# 4.0 并行计算部分 c#linq算法多线程list微软 目录(?)[-] C 40 并行计算部分 一简单使用 二 并行循环的中断和跳出 三并行循环中为数组集合添加项 四返回集合运算结果 ...
- eclipse中多个工程编译到同一个目录下
1.点击link source 2.选择Java(ps:Java文件目录)或者resource(ps:配置文件目录) 3.最后结果,然后使用project中的clean进行编译,就可以把两个工程编 ...
- hdu1064Financial Management
Problem Description Larry graduated this year and finally has a job. He’s making a lot of money, but ...
- UVA 227 Puzzle - 输入输出
题目: acm.hust.edu.cn/vjudge/roblem/viewProblem.action?id=19191 这道题本身难度不大,但输入输出时需要特别小心,一不留神就会出问题. 对于输入 ...
- Linux下VMWare虚拟机的使用技巧
使用技巧: 1.虚拟机安装文件:vm-workstation-full-8.0.3-703057.x86_64.bundle,./vm-workstation-full-8.0.3-703057.x8 ...