●POJ 1195 Mobile phones
题链:
http://poj.org/problem?id=1195
题解:
二维树状数组
#include<cstdio>
#include<cstring>
#include<iostream>
#define MAXN 1500
using namespace std;
struct BIT{
int val[MAXN][MAXN],N;
void Reset(int n){N=n; memset(val,0,sizeof(val));}
int Lowbit(int x){return x&-x;}
void Modify(int x,int y,int v){
x++; y++;
for(int i=x;i<=N;i+=Lowbit(i))
for(int j=y;j<=N;j+=Lowbit(j))
val[i][j]+=v;
}
int Sum(int x,int y){
int ret=0;
for(int i=x;i;i-=Lowbit(i))
for(int j=y;j;j-=Lowbit(j))
ret+=val[i][j];
return ret;
}
int Area(int x1,int y1,int x2,int y2){
x1++; y1++; x2++; y2++;
return Sum(x2,y2)-Sum(x1-1,y2)-Sum(x2,y1-1)+Sum(x1-1,y1-1);
}
}DT;
int main(){
int cm,a,b,c,d;
scanf("%d%d",&cm,&a);
DT.Reset(a);
while(~scanf("%d",&cm)&&cm!=3){
if(cm==1) scanf("%d%d%d",&a,&b,&c),DT.Modify(a,b,c);
else scanf("%d%d%d%d",&a,&b,&c,&d),printf("%d\n",DT.Area(a,b,c,d));
}
return 0;
}
●POJ 1195 Mobile phones的更多相关文章
- poj 1195:Mobile phones(二维树状数组,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14489 Accepted: 6735 De ...
- poj 1195:Mobile phones(二维线段树,矩阵求和)
Mobile phones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 14391 Accepted: 6685 De ...
- (简单) POJ 1195 Mobile phones,二维树状数组。
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- POJ 1195 Mobile phones(二维树状数组)
Mobile phones Time Limit: 5000MS Mem ...
- POJ 1195 Mobile phones (二维树状数组)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- 题解报告:poj 1195 Mobile phones(二维BIT裸题)
Description Suppose that the fourth generation mobile phone base stations in the Tampere area operat ...
- poj 1195 Mobile phones(二维树状数组)
树状数组支持两种操作: Add(x, d)操作: 让a[x]增加d. Query(L,R): 计算 a[L]+a[L+1]……a[R]. 当要频繁的对数组元素进行修改,同时又要频繁的查询数组内任一 ...
- poj 1195 Mobile phones 解题报告
题目链接:http://poj.org/problem?id=1195 题目意思:有一部 mobie phone 基站,它的面积被分成一个个小正方形(1 * 1 的大小),所有的小正方形的面积构成了一 ...
- poj 1195 - Mobile phones(树状数组)
二维的树状数组,,, 记得矩阵的求和运算要想好在写.... 代码如下: #include <cstdio> #include <cstdlib> #include <cm ...
随机推荐
- 20162302 实验四《Android程序设计》实验报告
实 验 报 告 课程:程序设计与数据结构 姓名:杨京典 班级:1623 学号:20162302 实验名称:Android程序设计 实验器材:装有Android Studio的联想拯救者80RQ 实验目 ...
- 几款有用的AndroidStudio插件
1.Android Parcelable code generator 顾名思义,这是个生成实现了Parcelable接口的代码的插件. 在你的类中,按下alt + insert键弹出插入代码的上下文 ...
- Flask 学习 十四 测试
获取代码覆盖报告 安装代码覆盖工具 pip install coverage manage.py 覆盖检测 COV = None if os.environ.get('FLASK_COVERAGE') ...
- Flask 学习 九 用户资料
资料信息 app/models.py class User(UserMixin,db.Model): #...... name = db.Column(db.String(64)) location ...
- 第四十四条:为所有导出的API元素编写文档注释
简而言之,要为API编写文档,文档注释是最好,最有效的途径.对于所有可导出的API元素来说,使用文档注释应该被看作是强制性的.要 采用一致的风格来遵循标准的约定.记住,在文档注释内部出现任何的HTML ...
- 2017 清北济南考前刷题Day 3 afternoon
期望得分:100+40+100=240 实际得分:100+40+100=240 将每个联通块的贡献乘起来就是答案 如果一个联通块的边数>点数 ,那么无解 如果边数=点数,那么贡献是 2 如果边数 ...
- 关于TomCat上传文件中文名乱码的问题
最近在学习TomCat文件上传这一部分,由于文件上传必须要三个条件: 1.表单提交方式必须为Post 2.表单中需要有<input type="file">元素,还需要 ...
- JAVA_SE基础——5.第一个Java程序HelloWorld&注释的应用
配置完JDK&环境变量后,我们就可以开始写程序了,那么程序怎么写呢,用什么工具呢,我建议 为了方便学习,我们最好在一个磁盘下建立一个专门的文件来写java程序,比如就在D盘下建立一个名为&qu ...
- React Native学习(九)—— 使用Flexbox布局
本文基于React Native 0.52 Demo上传到Git了,有需要可以看看,写了新内容会上传的.Git地址 https://github.com/gingerJY/React-Native-D ...
- HTML的水平居中和垂直居中解决方案
水平居中:给div设置一个宽度,然后添加margin:0 auto属性 div{ width:200px; margin:0 auto; } 让绝对定位的div居中 div { position: a ...