POJ 1195 Mobile Phones
树状数组,开始的时候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的更多相关文章
- 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 题解: 二维树状数组 #include<cstdio> #include<cstring> #includ ...
- poj 1195 Mobile phones 解题报告
题目链接:http://poj.org/problem?id=1195 题目意思:有一部 mobie phone 基站,它的面积被分成一个个小正方形(1 * 1 的大小),所有的小正方形的面积构成了一 ...
- poj 1195 - Mobile phones(树状数组)
二维的树状数组,,, 记得矩阵的求和运算要想好在写.... 代码如下: #include <cstdio> #include <cstdlib> #include <cm ...
随机推荐
- isEmpty与null、""的区别
前一段时间我阅读别人的代码,发现有的时候用isEmpty,有的时候用null,有的时候用"".我很困惑三者之间的区别,于是我就自己写了一个程序来验证一下 public class ...
- Maven创建webapp(二)
这一节将记录在myeclipse下用maven创建一个简单的webapp项目 web开发maven仓库自动添加组件,故需要需要保持网络的通畅. 打开myeclipse --> File - ...
- CentOS6.5 安装Zookeeper集群
1.下载解压 2.配置环境变量:vi ~/.bashrc 或者 vi /etc/profile [hadoopuser@Linux01 ~]$ vi ~/.bashrc # zookeeper ...
- Sass学习之路(1)——Sass简介
Sass是CSS的一种预处理器语言,类似的语言还有Less,Stylus等. 那么什么是CSS预处理器? CSS 预处理器定义了一种新的语言,其基本思想是,用一种专门的编程语言,为 CSS 增加了一些 ...
- For循环语句的使用
一.For循环语句 说明:For循环用于循环次数已经确定的情况下. 格式:for(循环变量赋初值; 循环条件; 循环变量增值) { ·····语句 } 举例:求 ...
- FIM 2010: Kerberos Authentication Setup
The goal of this article is to provide some background information regarding the Kerberos related co ...
- 我在用的mac软件(1)--终端环境之iTerm2
之前一直有朋友要我分享下在用的mac软件,今天有空就来写一下,可能不止于软件,会有一些配置或者工具,或者叫环境更合适.有些可能一句话带过,有些会详细介绍.也不分类了,想到哪个就写出来.如果已经写的足够 ...
- Android-AsyncTask异步任务(获取手机联系人)
本篇随笔将讲解一下Android的多线程的知识,以及如何通过AsyncTask机制来实现线程之间的通信. 一.Android当中的多线程 在Android当中,当一个应用程序的组件启动的时候,并且没有 ...
- 全球最低功耗蓝牙单芯片DA14580的软件体系 -RW内核和消息处理机制
上一篇文章<蓝牙单芯片DA14580的硬件架构和低功耗>阐述了DA14580的硬件架构和低功耗的工作原理.本文文章阐述该平台的软件体系,并着重分析消息事件的处理机制. 一.DA14580S ...
- iOS 删除NSString中特定字符
+(NSString *) stringDeleteString:(NSString *)str { NSMutableString *str1 = [NSMutableString stringWi ...