题目链接:

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. 两个数据库通过DataTable实现差异传输

    两个主要方法 /// <summary>/// 用途:/// 用源表和目标表比较,返回差异的数据(目标表为参照物)/// /// 逻辑:/// 1.合并两个表/// 2.循环合并后得到的表 ...

  2. mybatis主键是在insert前生成还是之后生成

    oracle sequence 推荐每个表使用自己的sequence mysql 使用每个表的autoincreate来当主键 mybatis 操作insert时 主键的生成是在插入之前 还是之后? ...

  3. windows查看网络常用cmd命令

    一.ping 主要是测试本机TCP/IP协议配置正确性与当前网络现状.  ping命令的基本使用格式是: ping IP地址/主机名/域名 [-t] [-a] [-n count] [-l size] ...

  4. ettercap局域网DNS欺骗实现过程

    转载:https://www.cnblogs.com/hkleak/p/5043063.html 笔记一:ettercap是什么? 我们在对WEB安全检测的时候都会用到Cain和netfuke这两款工 ...

  5. my17_Mysql 主从切换

    注意事项: 从库提升为主库read_only要设置为OFF原主库改为从库后,read_only要设置ONread_only=ON并不能对root生效,确保root不会进行数据写入从主库进行 flush ...

  6. php数组·的方法3-数组指针

    /* * 数组指针函数 * */ //key() current() 指针一直停在第一位 不会下移 echo '<hr>'; $arr5 = array('name' => 'hxq ...

  7. Thinkphp3.2邮件发送

    第一步:加入这两个文件 第二部:在common的function中添加代码 function think_send_mail($to, $name, $subject = '', $body = '' ...

  8. 编译opencv python接口

    首先,安装依赖1 sudo apt-get install build-essential 2 sudo apt-get install cmake git libgtk2.0-dev pkg-con ...

  9. animition动画的加入

    很多时候我们把PopupWindow用作自定义的菜单,需要一个从底部向上弹出的效果,这就需要为PopupWindow添加动画. 在工程res下新建anim文件夹,在anim文件夹先新建两个xml文件 ...

  10. 实例化php类的时候如何传参

    当我们实例化一个php类的时候,要怎么传递参数呢?这取决于该类的构造方法. 例: person.class.php <?php class person{ var $name; var $col ...