●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 ...
随机推荐
- defaultdict使用及__missing__理解
import collections import re WORD_RE = re.compile(r'\w+') index = collections.defaultdict(list) #用li ...
- C++布隆过滤器
布隆过滤器 这名词有没有听着好像很 挺高大上的,的确,它也是一种很重要的结构,下面一起看看: 一:说说历史: (Bloom Filter)是由布隆(Burton Howard Bloom)在1970年 ...
- Linux学习--进程概念
>>进程 说进程,感觉好空洞,来一张图,Linux下的进程: ps -eo pid,comm,cmd 说明:-e表示列出全部进程,-o pid,comm,cmd表示我们需要PID,COMM ...
- 从PRISM开始学WPF(二)Prism?
目录: 从PRISM开始学WPF(一)WPF? 从PRISM开始学WPF(二)Prism? 从PRISM开始学WPF(三)Prism-Region? 从PRISM开始学WPF(四)Prism-Modu ...
- Linux基础常用命令
Linux 下命令有很多,并且很多命令用法又有不同的选项,这里介绍一些常用的最基本的Linux命令的用法,希望给大家留下便利之处. 1.cd 切换目录.例如 cd /home 可切换到home目录, ...
- vue class与style 绑定详解——小白速会
一.绑定class的几种方式 1.对象语法 直接看例子: <div id="app3"> <div :class="{'success':isSucce ...
- 织梦dedecms默认网站地图sitemap.html优化
网站地图对于网站优化很重要,搜索引擎就是靠网站地图去收录网站页面,本文主要讲解优化织梦自带的网站地图功能. 织梦自带的网站地图使用方法:织梦后台--生成--HTML更新--更新网站地图,可以在 ...
- Entity Framework Core Code First
参考地址:https://docs.microsoft.com/zh-cn/ef/core/get-started/aspnetcore/new-db
- 详解JavaScript对象继承方式
一.对象冒充 其原理如下:构造函数使用 this 关键字给所有属性和方法赋值(即采用类声明的构造函数方式).因为构造函数只是一个函数,所以可使 Parent 构造函数成为 Children 的方法,然 ...
- Vue 2.x + Webpack 3.x + Nodejs 多页面项目框架(下篇——多页面VueSSR+热更新Server)
Vue 2.x + Webpack 3.x + Nodejs 多页面项目框架(下篇--多页面VueSSR+热更新Server) @(HTML/JS) 这是Vue多页面框架系列文章的第二篇,上一篇(纯前 ...