题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1892

题目大意:

题目大意:有很多方格,每个方格对应的坐标为(I,J),刚开始时每个格子里有1本书,然后让你统计一片区域有多少本书,还可以增加书和减少,移动书。

解题思路:

直接二维数组数组模拟

注意:

每个下标+1,从(1, 1)开始

求区域和的时候给出的x1 y1 和x2 y2不是标准的正对角线,需要转化

  #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<list>
#include<deque>
#include<sstream>
#include<cctype>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, s, t) for(int i = (s); i < (t); i++)
#define MEM(a, x) memset(a, x, sizeof(a));
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = ;
const double eps = 1e-;
const int INF = << ;
const int dir[][] = {,,,,,-,-,};
const double pi = 3.1415926535898;
int T, n, m, cases;
int tree[maxn][maxn], a[maxn][maxn];
int lowbit(int x)
{
return x&(-x);
}
int sum(int x, int y)
{
int ans = ;
for(int i = x; i > ; i -= lowbit(i))
for(int j = y; j > ; j -= lowbit(j))
ans += tree[i][j];
return ans;
}
void add(int x, int y, int d)
{
for(int i = x; i < maxn; i += lowbit(i))
{
for(int j = y; j < maxn; j += lowbit(j))
{
tree[i][j] += d;
}
}
}
int main()
{
scanf("%d", &T);
char s[];
int x, y, x1, y1, x2, y2, d;
while(T--)
{
scanf("%d", &n);
MEM(tree, );
for(int i = ; i < maxn; i++)
{
for(int j = ; j < maxn; j++)
{
add(i, j, );
a[i][j] = ;
}
}
printf("Case %d:\n", ++cases);
while(n--)
{
scanf("%s", s);
if(s[] == 'S')
{
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
///不是标准的x1<x2, y1<y2,要对其进行转化
int a, b, c, d;
a = min(x1, x2);a++;
b = min(y1, y2);b++;
c = max(x1, x2);c++;
d = max(y1, y2);d++;
printf("%d\n", sum(c, d) + sum(a - , b - ) - sum(a - , d) - sum(c, b - ));
}
else if(s[] == 'A')
{
scanf("%d%d%d", &x, &y, &d);
x++, y++;
add(x, y, d);
a[x][y] += d;
}
else if(s[] == 'D')
{
scanf("%d%d%d", &x, &y, &d);
x++, y++;
if(d > a[x][y])d = a[x][y];
add(x, y, -d);
a[x][y] -= d;
}
else
{
scanf("%d%d%d%d%d", &x1, &y1, &x2, &y2, &d);
x1++, y1++, x2++, y2++;
if(d > a[x1][y1])d = a[x1][y1];
add(x1, y1, -d);
add(x2, y2, d);
a[x1][y1] -= d;
a[x2][y2] += d;
}
}
}
return ;
}

hdu-1892 See you~---二维树状数组运用的更多相关文章

  1. HDU 1892(书架统计 二维树状数组)

    题意是在二维平面上在一些位置上进行数据的增删改查操作,使用树状数组(了解树状数组点这里) 原来的树状数组在求区间和时是 sum( x, y ) = getsum( y ) - getsum( x - ...

  2. HDU 1892 See you~ (二维树状数组)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1892 See you~ Problem Description Now I am leaving h ...

  3. 【 HDU - 4456 】Crowd (二维树状数组、cdq分治)

    BUPT2017 wintertraining(15) #5A HDU 4456 题意 给你一个n行n列的格子,一开始每个格子值都是0.有M个操作,p=1为第一种操作,给格子(x,y)增加z.p=2为 ...

  4. hdu 2642 Stars 【二维树状数组】

    题目 题目大意:Yifenfei是一个浪漫的人,他喜欢数天上的星星.为了使问题变得更容易,我们假设天空是一个二维平面,上面的星星有时会亮,有时会发暗.最开始,没有明亮的星星在天空中,然后将给出一些信息 ...

  5. hdu 5517 Triple(二维树状数组)

    Triple Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Sub ...

  6. HDU 5517---Triple(二维树状数组)

    题目链接 Problem Description Given the finite multi-set A of n pairs of integers, an another finite mult ...

  7. HDU 5517 【二维树状数组///三维偏序问题】

    题目链接:[http://acm.split.hdu.edu.cn/showproblem.php?pid=5517] 题意:定义multi_set A<a , d>,B<c , d ...

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

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

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

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

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

    二维树状数组 单点更新区间查询 模板 从零开始借鉴http://www.2cto.com/kf/201307/227488.html #include<stdio.h> #include& ...

随机推荐

  1. Linux系统lvm管理

    pv:   物理卷,被pv命令处理过的物理分区vg:物理卷组        被组装到一起的物理卷pe: 物理扩展        lvm设备的最小存储单元    lvm是pe的整数倍lvm:逻辑卷    ...

  2. Go语言基础之7--函数详解

    一. 函数介绍 1.1 定义 函数:有输入.有输出,用来执行一个指定任务的代码块. func functionname([parametername type]) [return type] { // ...

  3. 需要了解的几个Java基础点

    关键字 native:表示要调用非Java语言写函数,比如用C语言使用JNI实现的接口.比如windows环境的dll文件.举例:Object.hashcode() 位运算 << n:左移 ...

  4. Java StringBuffer

    String是不变类,用String修改字符串会新建一个String对象,如果频繁的修改,将会产生很多的String对象,开销很大.因此java提供了一个StringBuffer类,这个类在修改字符串 ...

  5. .net core项目中引用.net framework封装的dll库

    https://blog.csdn.net/sharphou/article/details/80746551   A----------如何安装IIS [Server Hosting]------- ...

  6. 在vue2.x中安装sass并配置

    在vue中安装sass先检查系统中有没有安装sass,在命令行中输入 sass -v 表示sass在电脑中已有,否者可以参考我这篇博客安装Sass遇到的坑 一.先安装sass cmd打开命令行,到项目 ...

  7. java源文件组成部分

    class HelloWorld{ public static void main(String[ ] args) { System.out.print("HelloWorld!!!&quo ...

  8. VUE环境搭建及打包上线

    1.vue2.0新手填坑攻略之使用vue-cli搭建vue项目开发环境到项目发布 https://blog.csdn.net/u010020858/article/details/72865101 2 ...

  9. elastic search语句

    基本匹配: { "query":{ "match":{ "title" : "quick" } } } ES语法结构: ...

  10. ubuntu下安装wireshark(以及配置非root)

    https://jingyan.baidu.com/article/c74d60009d992f0f6a595de6.html Wireshark是世界上最流行的网络分析工具.这个强大的工具可以捕捉网 ...