题目连接:

题意:要求设计这样一个数据结构,支持下列操作

1.add(x,y,a).对二维数组的第x行,第y列加上a.

2.sum(l,b,r,t).求所有满足l<=x<=r,b<=y<=t,的数组元素的和

二位树状数组~

 #include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define loop(s,i,n) for(i = s;i <= n;i++)
#define lowbit(x) x&-x
using namespace std;
int c[][];
int n;
void add(int a,int b,int val)
{
int i,j;
for(i = a;i <= n;i += lowbit(i))
{
for(j = b;j <= n;j += lowbit(j))
c[i][j] += val;
}
} int sum(int a,int b)
{
int res = ;
int i,j;
for(i = a;i > ;i -= lowbit(i))
{
for(j = b;j > ;j -= lowbit(j))
res+=c[i][j];
}
return res;
}
int main()
{
int t,i,j,a,b,l,r;
while(~scanf("%d",&t) != EOF)
{
if(!t)
{
scanf("%d",&n);
loop(,i,n)
{
loop(,j,n)
c[i][j] = ;
}
}
if(t == )
{
scanf("%d %d %d",&a,&b,&l);
add(a+,b+,l);
}
else if(t == )
{
scanf("%d %d %d %d",&a,&b,&l,&r);
printf("%d\n",sum(a,b)+sum(l+,r+)-sum(a,r+)-sum(l+,b));
}
if(t == )
break;
}
return ;
}

poj 1195 mobile phone的更多相关文章

  1. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  2. poj 1195:Mobile phones(二维线段树,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14391   Accepted: 6685 De ...

  3. poj 1195 Mobile phones(二维树状数组)

    树状数组支持两种操作: Add(x, d)操作:   让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...

  4. (简单) POJ 1195 Mobile phones,二维树状数组。

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  5. ●POJ 1195 Mobile phones

    题链: http://poj.org/problem?id=1195 题解: 二维树状数组 #include<cstdio> #include<cstring> #includ ...

  6. poj 1195 Mobile phones 解题报告

    题目链接:http://poj.org/problem?id=1195 题目意思:有一部 mobie phone 基站,它的面积被分成一个个小正方形(1 * 1 的大小),所有的小正方形的面积构成了一 ...

  7. POJ 1195 Mobile phones(二维树状数组)

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

  8. POJ 1195 Mobile phones (二维树状数组)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  9. 题解报告:poj 1195 Mobile phones(二维BIT裸题)

    Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...

  10. poj 1195 - Mobile phones(树状数组)

    二维的树状数组,,, 记得矩阵的求和运算要想好在写.... 代码如下: #include <cstdio> #include <cstdlib> #include <cm ...

随机推荐

  1. Cloud Insight支持阿里云一键接入了,so what?

    前几天 Cloud Insight 上线了一个新功能,考虑到目前只作为公测,所以只是是悄悄地加了一个接入项,希望你看完这偏文章会有兴趣体验一下. 相信体验过的用户(目前还是个位数)第一感受应该是:这个 ...

  2. C#&java重学笔记(函数)

    C#部分  1.写在函数定义的()中的关键字: a.params关键字:用来满足函数的参数为数组时,而数组的长度不固定的情况.且该关键字只能用来修饰数组型参数.这样一修饰,就达成了类似JavaScri ...

  3. Subclasses

    Given a collection of numbers, return all possible subclasses. public class Solution { public List&l ...

  4. HDU 4597 Play Game(记忆化搜索,深搜)

    题目 //传说中的记忆化搜索,好吧,就是用深搜//多做题吧,,这个解法是搜来的,蛮好理解的 //题目大意:给出两堆牌,只能从最上和最下取,然后两个人轮流取,都按照自己最优的策略,//问说第一个人对多的 ...

  5. C# WINFORM 捕获全局异常

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Thr ...

  6. Jmeter正则表达式提取器的使用方法(转)

    下面简单介绍一下Jmeter正则表达式提取器的使用方法. 1.添加Jmeter正则表达式提取器:在具体的Request下添加Jmeter正则表达式提取器(Jmeter正则表达式在“后置处理器”下面)  ...

  7. 修改bigbluebutton白板上传中文乱码

          中文命名的文档,上传是乱码 -- 显示的 打开后, 中文部分是乱码 Comment 1 by project member ffdixon, Nov 08, 2010 Translatio ...

  8. JavaWeb项目开发案例精粹-第4章博客网站系统-004Service层

    1. package com.sanqing.service; import java.util.List; import com.sanqing.fenye.Page; import com.san ...

  9. linux shell 命令学习(2) paste - merge lines of files

    paste - merge lines of files 命令格式: paste [OPTION] ... [FILE] ... 说明: 输出每个文件的对应行组合而成的行,中间用tab分开,如果没有F ...

  10. Linux 下sleep()函数

    调试程序发现起了一个子线程后,主线程上的sleep不生效了,看到这才明白... — Function: unsigned int sleep (unsigned int seconds) The sl ...