●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 ...
随机推荐
- C语言第四次博客作业
一.PTA实验作业 题目1.梅森数 1.本题PTA提交列表(要提交列表,不是结果) 2. 设计思路(此处用流程图最好) 1.定义三个变量n,num,count,且初始化count为1 2.读取一个数n ...
- STL常用整理
S T L Sting: << 判断拼音序 size length 字符串长度 str[n] 代表字符串中的一个字符 可用作左值 string::size_type 用于表示字符串长度计量 ...
- Django 视图层
URL映射 1.分布式url映射 include()函数提供分布式url映射功能,使URL映射可以被编写在多个url.py文件中 from django.conf.urls import url fr ...
- 使用caffe训练mnist数据集 - caffe教程实战(一)
个人认为学习一个陌生的框架,最好从例子开始,所以我们也从一个例子开始. 学习本教程之前,你需要首先对卷积神经网络算法原理有些了解,而且安装好了caffe 卷积神经网络原理参考:http://cs231 ...
- xxe漏洞检测及代码执行过程
这两天看了xxe漏洞,写一下自己的理解,xxe漏洞主要针对webservice危险的引用的外部实体并且未对外部实体进行敏感字符的过滤,从而可以造成命令执行,目録遍历等.首先存在漏洞的web服务一定是存 ...
- django的FBV和CBV
title: python djano CBV FBV tags: python, djano, CBV, FBV grammar_cjkRuby: true --- python django的fu ...
- LeetCode & Q20-Valid Parentheses-Easy
Stack String Description: Given a string containing just the characters '(', ')', '{', '}', '[' and ...
- 新概念英语(1-115)Knock! Knock!
Lesson 115 Knock, knock! 敲敲门! Listen to the tape then answer this question. What does Jim have to dr ...
- SVN (TortioseSVN) 版本控制之忽略路径(如bin、obj、gen)
在SVN版本控制时,新手经常会遇到这样的问题: 1.整个项目一起提交时会把bin . gen . .project 一同提交至服务器 2.避免提交编译.本地配置等文件在项目中单独对src.res进行提 ...
- 在Linux的Terminal中显示文本文件特定行的内容
假设要操纵的文本文件的文件名是 textFile现在想做的事情是在不以编辑模式打开文件的情况下在终端直接提取并输出指定文本文件的指定行的内容 在终端提取指定文本文件的指定行的内容 Tool Comma ...