poj 2115 Matrix
题意:
给出一个矩阵,有两种操作:
1.翻转给定的子矩阵;
2.查询a[i][j]的值。
思路:
树状数组是从小到大更新的。
这个题用二维树状数组可以解决,假设是一维树状数组,
0 0 0 0 0 0
我们把第三个到第四个翻转,变成
0 0 1 1 -1 0
sum[1] = 0,sum[2] = 0,sum[3] = 1,sum[4] = 1,sum[5] = 0,sum[6] = 0
所以类似一维的bit,但是要用到容斥原理,多减的要加回来。
代码:
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = ;
int c[N][N];
int n;
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int y)
{
for (int i = x;i <= n;i += lowbit(i))
{
for (int j = y;j <= n;j += lowbit(j))
{
c[i][j] += ;
}
}
}
int getsum(int x,int y)
{
int ans = ;
for (int i = x;i > ;i -= lowbit(i))
{
for (int j = y;j > ;j -= lowbit(j))
{
ans += c[i][j];
}
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
int op;
scanf("%d%d",&n,&op);
memset(c,,sizeof(c));
while (op--)
{
char s[];
scanf("%s",s);
if (s[] == 'C')
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
add(x1,y1);
add(x2 + ,y1);
add(x1,y2 + );
add(x2 + ,y2 + );
}
if (s[] == 'Q')
{
int x,y;
scanf("%d%d",&x,&y);
int ans = getsum(x,y);
if (ans % ) puts("");
else puts("");
}
}
if (T) puts("");
}
return ;
}
poj 2115 Matrix的更多相关文章
- POJ 2115 C Looooops(扩展欧几里得应用)
题目地址:POJ 2115 水题. . 公式非常好推.最直接的公式就是a+n*c==b+m*2^k.然后能够变形为模线性方程的样子,就是 n*c+m*2^k==b-a.即求n*c==(b-a)mod( ...
- POJ poj 2155 Matrix
题目链接[http://poj.org/problem?id=2155] /* poj 2155 Matrix 题意:矩阵加减,单点求和 二维线段树,矩阵加减,单点求和. */ using names ...
- 【题解】POJ 2115 C Looooops (Exgcd)
POJ 2115:http://poj.org/problem?id=2115 思路 设循环T次 则要满足A≡(B+CT)(mod 2k) 可得 A=B+CT+m*2k 移项得C*T+2k*m=B-A ...
- 矩阵十点【两】 poj 1575 Tr A poj 3233 Matrix Power Series
poj 1575 Tr A 主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1575 题目大意:A为一个方阵,则Tr A表示A的迹(就是主对角线上各项的 ...
- POJ 2155 Matrix
二维树状数组.... Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissio ...
- poj 2155:Matrix(二维线段树,矩阵取反,好题)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17880 Accepted: 6709 Descripti ...
- POJ 2155 Matrix (二维线段树)
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17226 Accepted: 6461 Descripti ...
- poj 3685 Matrix(二分搜索之查找第k大的值)
Description Given a N × N matrix A, whose element × i + j2 - × j + i × j, you are to find the M-th s ...
- POJ 2155 Matrix (D区段树)
http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 1 ...
随机推荐
- office图标(word,powerpoint,excel)异常(变成白板)问题修复
都是wps搞的鬼. 如果先装了wps后卸载wps再装office就可能出现这个问题. 终于解决了!!先装个wps 2016,进入设置→高级→兼职性关联.这时你会发现ppt文件图标不是白板了.重启打开w ...
- IE下CSS3伪类的支持
当css3.0出现以后,着实让我兴奋了好久,因为出现了很多选择器,我们在也不用靠js做复杂判断了.比如:nth-child,很容易就可以判断奇偶对象 “:nth-child(2n)和:nth-chil ...
- Solve fatal error: helper_math.h: No such file or directory
When the 'fatal error: helper_math.h: No such file or directory' occurs, it means the 'helper_math.h ...
- git开发过程中的使用流程
001.创建仓库 002.新建项目 003.初始化仓库 这一步不需要做 git init : 文件夹中会多出一个隐藏的.git文件 004.克隆项目 git clone <项目地址> 0 ...
- atom编辑器安装插件报错。。
Checking for native build tools failed gyp info it worked if it ends with ok gyp info using node-gyp ...
- 【LookLook文档】通过less 定制自己的Bootstrap 样式
闲话 学习还是看文档最快,看文档要仔细点,不可走马观花.感谢 “Bootstrap中文网” 思路 1.早在2015开始接触,由于公司中使用的是easyui 固一直没完全使用Bootstrap,开始接触 ...
- php composer windows安装
2018年6月22日10:40:49 笔记 1.先下载Composer-Setup.exe,下载地址:http://docs.phpcomposer.com/00-intro.html#Install ...
- 关于python列表和元组的基本操作
一.列表 列表是python中最常出现的一种数据存储形式,掌握列表的基本操作可以快速而有效的提高我们的代码书写效率.列表中存放的数据有如下基本操作:如增.删.改.查,掌握了这四个操作,就基本掌握了列表 ...
- 初识Restful架构
1.对Rest(Restful)的理解 理解RESTful架构 怎样用通俗的语言解释REST,以及RESTful 维基百科:Representational state transfer 2.Rest ...
- filter 过滤器的基本使用
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...