题目链接:

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. 工具类_IsNull

    import java.util.List; /** * 判断是否为空 2015-08-17 *  * @author lipanquan *  */public final class IsNull ...

  2. Go语言基础之18--接口编程

    一.接口介绍和定义 1.1 接口定义了一个对象的行为规范 A. 只定义规范,不实现 B. 具体的对象需要实现规范的细节 葵花宝典: 接口就是一层封装,1个例子,封装一个返还浏览器内容的接口.为什么不直 ...

  3. maven set MAVEN_OPTS

    http://juvenshun.iteye.com/blog/240257 https://docs.alfresco.com/5.1/tasks/alfresco-sdk-install-mave ...

  4. oracle Clob类型转换成String类型

    转载:https://www.cnblogs.com/itmyhome/p/4131339.html Clob类型转换成String类型 oracle中表结构如下: create table GRID ...

  5. codeforces之4.1学习记录

    记录一些之前没见过的代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF ...

  6. DRF接入Oauth2.0认证[微博登录]报错21322重定向地址不匹配

    DRF接入Oauth2.0认证[微博登录]报错21322重定向地址不匹配 主题自带了微博登陆接口,很简单的去新浪微博开放平台创建了网页应用,然后把APP ID和 AppSecret填好后,以为大功告成 ...

  7. 使用bootstrap创建上传文件

    1.导入样式,注意顺序 <!-- bootstrap样式 --> <link rel="stylesheet" href="/static/bootst ...

  8. Unity Screen Screen.currentResolution 当前分辨率

    The current screen resolution (Read Only). 当前屏幕的分辨率.(只读) If the player is running in window mode, th ...

  9. 性能测试工具LoadRunner01-性能测试基础

    什么是性能测试? 在一定的约束条件下(指定的软件.硬件.网络环境等)对产品按一定的性能指标进行测试,确定系统能承受的最大负载压力,解决性能瓶颈.给用户最好的体验. 性能测试流程? 什么时候开始性能测试 ...

  10. [引]雅虎日历控件 Example: Two-Pane Calendar with Custom Rendering and Multiple Selection

    本文转自:http://yuilibrary.com/yui/docs/calendar/calendar-multipane.html This example demonstrates how t ...