HDU 5465——Clarke and puzzle——————【树状数组BIT维护前缀和+Nim博弈】
Clarke and puzzle
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 673 Accepted Submission(s): 223
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.
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.
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.
int sum(int x,int y){
int ret=0;
for(int i=x;i>0;i-=lowbit(i)){
for(int j=y;j>0;j-=lowbit(j)){
ret+=C[i][j];
}
}
return ret;
}
修改:
void modify(int x,int y,int val){
for(int i=x;i<=n;i+=lowbit(i)){
for(int j=y;j<=m;j+=lowbit(j)){
C[i][j] += val;
}
}
}
#include<bits/stdc++.h>
using namespace std;
typedef long long INT;
const int maxn=550;
int a[maxn][maxn];
int C[maxn][maxn];
int n,m;
int lowbit(int x){
return x & (-x);
}
void modify(int x,int y,int val){
for(int i=x;i<=n;i+=lowbit(i)){
for(int j=y;j<=m;j+=lowbit(j)){
C[i][j] ^= val;
}
}
}
int sum(int x,int y){
int ret=0;
for(int i=x;i>0;i-=lowbit(i)){
for(int j=y;j>0;j-=lowbit(j)){
ret ^=C[i][j];
}
}
return ret;
}
int main(){
int t,q;
scanf("%d",&t);
while(t--){
memset(a,0,sizeof(a));
memset(C,0,sizeof(C));
scanf("%d%d%d",&n,&m,&q);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
scanf("%d",&a[i][j]);
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
modify(i,j,a[i][j]);
}
}
int typ,x1,x2,y1,y2,c;
for(int i=0;i<q;i++){
scanf("%d",&typ);
if(typ==1){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int ans1,ans2,ans3,ans4;
ans1=sum(x2,y2);
ans2=sum(x2,y1-1);
ans3=sum(x1-1,y2);
ans4=sum(x1-1,y1-1);
int ans=ans1^ans2^ans3^ans4;
printf("%s\n",ans==0?"No":"Yes");
}else{
scanf("%d%d%d",&x1,&y1,&c);
modify(x1,y1,c^a[x1][y1]);
a[x1][y1]=c;
}
}
}
return 0;
}
HDU 5465——Clarke and puzzle——————【树状数组BIT维护前缀和+Nim博弈】的更多相关文章
- HH的项链 树状数组动态维护前缀
#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const ...
- HDU 5465 Clarke and puzzle Nim游戏+二维树状数组
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5465 Clarke and puzzle Accepts: 42 Submissions: 26 ...
- hdu 5592 ZYB's Game 树状数组
ZYB's Game Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=55 ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- hdu 5517 Triple(二维树状数组)
Triple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- 「BZOJ1537」Aut – The Bus(变形Dp+线段树/树状数组 最优值维护)
网格图给予我的第一反应就是一个状态 f[i][j] 表示走到第 (i,j) 这个位置的最大价值. 由于只能往下或往右走转移就变得显然了: f[i][j]=max{f[i-1][j], f[i][j-1 ...
- HDU 1394 Minimum Inversion Number ( 树状数组求逆序数 )
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 Minimum Inversion Number ...
- HDU 5862 Counting Intersections (树状数组)
Counting Intersections 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 Description Given ...
- HDU 1394 Minimum Inversion Number (树状数组求逆序对)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题目让你求一个数组,这个数组可以不断把最前面的元素移到最后,让你求其中某个数组中的逆序对最小是多 ...
随机推荐
- js提交数据时需判断是点击事件还是回车键
使用回车键实质还是点击事件==回车时将焦点聚居在某个标签上. Html代码: <div id="btlogin" class="btlogin">& ...
- iOS使用VideoToolbox硬编码录制H264视频
http://blog.csdn.net/shawnkong/article/details/52045894
- 杭电acm 1033题
Problem Description For products that are wrapped in small packings it is necessary that the sheet o ...
- PCLVisualizer可视化类(4)
博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=168 多视口显示 所示,并进行比较分析,利用不同的搜索半径,基于同一点云计算 ...
- [转]hadoop运行mapreduce作业无法连接0.0.0.0/0.0.0.0:10020
14/04/04 17:15:12 INFO mapreduce.Job: map 0% reduce 0% 14/04/04 17:19:42 INFO mapreduce.Job: map 4 ...
- hdu1065
#include <stdio.h> int main() { int t; double x, y; scanf("%d", &t); for; i < ...
- c# 指针unsafe/fixed -- 【一】
指针C#unsafefixed 目录(?)[-] 概述 unsafe fixed 1.1 概述 unsafe关键字表示不安全上下文,该上下文是任何涉及指针的操作所必需的.可以在属性.方法.类的声明中使 ...
- 《Linux内核设计与实现》读书笔记(二)- 内核开发的准备
在尝试内核开发之前,需要对内核有个整体的了解. 主要内容: 获取内核源码 内核源码的结构 编译内核的方法 内核开发的特点 1. 获取内核源码 内核是开源的,所有获取源码特别方便,参照以下的网址,可以通 ...
- sql server列转行的几种方法
方法一,临时变量: declare @temp nvarchar(max)='' select @temp=coalesce(@temp,'')+Location+',' from( select d ...
- JSONCPP开发环境搭建
环境设置 项目地址 https://github.com/open-source-parsers/jsoncpp.git 操作系统 64位 Fedora 24 安装jsoncpp $ git clon ...