树状数组,开始的时候wa了,后来看看,原来是概率论没学好,以为求(L,B) - (R,T) 矩阵内的和只要用sum(R+1,T+1) - sum(L,B) 就行了,。傻x了。。

必须 sum(R,T) - sum(L,T) - sum(R,B) + sum(L,B) ;  (R,T 已经自加1)   诫之。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1027 int c[N][N];
int n; int lowbit(int x)
{
return x&(-x);
} void modify(int x,int y,int val)
{
for(int i=x;i<=n;i+=lowbit(i))
{
for(int j=y;j<=n;j+=lowbit(j))
{
c[i][j] += val;
}
}
} int sum(int x,int y)
{
int res = ;
for(int i=x;i>;i-=lowbit(i))
{
for(int j=y;j>;j-=lowbit(j))
{
res += c[i][j];
}
}
return res;
} int main()
{
int op,L,B,R,T,A,X,Y;
while(scanf("%d",&op)!=EOF)
{
if(op == )
break;
else if(op == )
{
memset(c,,sizeof(c));
scanf("%d",&n);
}
else if(op == )
{
scanf("%d%d%d",&X,&Y,&A);
X++;Y++;
modify(X,Y,A);
}
else if(op == )
{
scanf("%d%d%d%d",&L,&B,&R,&T);
R++;T++;
printf("%d\n",sum(R,T)-sum(L,T)-sum(R,B)+sum(L,B));
}
}
return ;
}

POJ 1195 Mobile Phones的更多相关文章

  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,二维树状数组。

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

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

                                                                  Mobile phones Time Limit: 5000MS   Mem ...

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

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

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

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

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

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

  8. ●POJ 1195 Mobile phones

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

  9. poj 1195 Mobile phones 解题报告

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

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

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

随机推荐

  1. Android Studio使用教程(二)

    以下是本次Google I/O大会发布的IDE Android Studio使用教程第二篇: 在Android Studio使用教程(一)中简要介绍了Android Studio的基本使用,包括安装. ...

  2. (六)play之yabe项目【验证码】

    (六)play之yabe项目[验证码] 博客分类: 框架@play framework   添加验证码功能 在Application.java中添加一个action:captcha() /** * 添 ...

  3. abap 选择屏幕事件AT SELECTION-SCREEN

    AT SELECTION-SCREEN (1).其实就像一个FORM,所以在这个事件里声明的变量都是局部变量. (2).根据SY-UCOMM这个系统变量可以判断用户的命令 (3).在这个事件里响应的是 ...

  4. MySQL数据库的基本数据类型

    整数类型 数值型数据类型主要用来存储数字,包含的类型有: TINYINT.SMALLINT.MEDIUMINT. INT(INTEGER). BIGINT. 下面通过一个例子来查看各种类型的所占有的数 ...

  5. Displaying SharePoint Lists or Libraries in other sites 显示其他站点的List

    Child objects within SharePoint, like a list in a Site, share an inherent connection with that Paren ...

  6. HillStone上网认证客户端

    公司上网认证服务器从原来网康变更成山石(HillStone),原来网康是有认证客户端的,运行在系统托盘区,现在的Hillstone是通过网页页面认证的,要上网,这个认证页面就需要一直打开在那里.碰到异 ...

  7. dom4j创建xml

    在前边介绍SAX,PULL等等既然能解析,当然也能生成.不过这里介绍dom4j创建xml文件,简单易懂. dom4j是独立的api,官网:http://www.dom4j.org/    可以去这下载 ...

  8. Android—SQLITE数据库的设计和升降级

    Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大.SQLite具备下列特点: 1.轻量级 使用 SQLite 只需要带一个动 ...

  9. iOS 杂笔-21(self.name = “object” 和 _name =”object” 有什么不同?)

    iOS 杂笔-21(self.name = "object" 和 _name ="object" 有什么不同?) 问题如题,这是考察对属性与变量的了解而已. s ...

  10. C++中的多态与虚函数的内部实现

    1.什么是多态         多态性可以简单概括为“一个接口,多种行为”.         也就是说,向不同的对象发送同一个消息, 不同的对象在接收时会产生不同的行为(即方法).也就是说,每个对象可 ...