●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 ...
随机推荐
- 网易云音乐APP分析
网易云音乐-感受音乐的力量 你选择的产品是? 网易云音乐 为什么选择该产品作为分析? 之前用的一直是QQ音乐,但是有一天一个朋友分享了一首网易云上的音乐(顺便分享一下歌名:Drop By Drop) ...
- 网络1711-1712班 c 语言评分总表一览
学号 姓名 作业地址 PTA实验作业5分 PTA排名2分 阅读代码2分 总结1分 代码规范扣分-2--0 总分 是否推荐博客 1 **莹 http://www.cnblogs.com/wwwwxy12 ...
- Oracle查询用户权限
Oracle查询用户权限 -- 确定角色的权限select * from role_tab_privs ; 包含了授予角色的对象权限select * from role_ro ...
- iOS开发-即时通信XMPP
1. 即时通信 1> 概述 即时通讯(Instant Messaging)是目前Internet上最为流行的通讯方式,各种各样的即时通讯软件也层出不穷,服务提供商也提供了越来越丰富的通讯服务功能 ...
- poj 2142 The Balance
The Balance http://poj.org/problem?id=2142 Time Limit: 5000MS Memory Limit: 65536K Descripti ...
- excel2003和excel2007文件的创建和读取
excel2003和excel2007文件的创建和读取在项目中用的很多,首先我们要了解excel的常用组件和基本操作步骤. 常用组件如下所示: HSSFWorkbook excel的文档对象 HSSF ...
- php中(包括织梦cms)set_time_limit(0)不起作用的解决方法
背景介绍: 在做织梦冗余图片清理的功能时, 由于冗余图片太多,导致每次清理时都会超时, 后来在网上搜索了各种文章,网上有如下的解决方法: set_time_limit(0) ini_set('max_ ...
- CSS <input type="file">样式设置
这是最终想要的效果~~~ 实现很简单,div设置背景图片,<input type="file"/>绝对定位上去再设置opacity:0(透明度为0 ) 直接上代码,希望 ...
- IDEA插件和快捷设置
前言 IDEA全名Intellij IDEA,是Java开发的集成环境,它有两个版本,专业版(Ultimate)和社区版(Community),专业版需要注册,而社区版不用注册,同时需要注意的是社区版 ...
- 区间的连续段~ST表(模板题)
链接:https://www.nowcoder.com/acm/contest/82/B来源:牛客网 时间限制:C/C++ 7秒,其他语言14秒 空间限制:C/C++ 262144K,其他语言5242 ...