poj 1195 mobile phones
来源:互联网 发布:app数据库设计 编辑:程序博客网 时间:2024/05/16 09:11
二维树状数组中
sum(x,y)表示从0~x,0~y范围区间内的和,包括0,0,x,y
#include<iostream>using namespace std;int c[1050][1050],size;int lowbit(int x);void modify(int x,int y,int v);int sum(int x,int y);int main(){int n;while(scanf("%d",&n)){int X,Y,A,L,B,R,T;int flag = 0;switch(n){ case 0: scanf("%d",&size);break; case 1: scanf("%d%d%d",&X,&Y,&A); modify(X,Y,A);break; case 2: scanf("%d%d%d%d",&L,&B,&R,&T); printf("%d\n",sum(R,T) - sum(L-1,T) - sum(R,B-1) + sum(L-1,B-1)); //减去sum(l-1,t),sum(r,b-1)时重复了sum(l-1,b-1) 题目要求的是L<= X <=R B<= Y <=T 包括了边界所以要减1 break; case 3: flag = 1;break;}if(flag)break;}return 0;}int lowbit(int x){return x&(-x);}void modify(int x,int y,int v){x++;y++; //使得数组下标从1开始而不是从0开始int i = x,j;while(i <= size){j = y;while(j <=size){c[i][j] += v;j += lowbit(j);}i += lowbit(i);}}int sum(int x,int y){x++;y++;int i = x,j,ans = 0;while(i > 0){j = y;while(j > 0){ans += c[i][j];j -= lowbit(j);}i -= lowbit(i);}return ans;}
- POJ 1195 Mobile phones
- poj 1195 Mobile phones
- poj 1195 Mobile phones
- poj 1195 mobile phones
- POJ 1195 Mobile phones
- Poj 1195 Mobile phones
- poj 1195 Mobile phones
- POJ 1195 Mobile phones
- POJ 1195 Mobile phones
- POJ 1195 Mobile phones
- POJ 1195 Mobile phones
- POJ 1195 Mobile phones
- poj 1195 Mobile phones
- poj 1195 Mobile phones
- POJ 1195 Mobile phones
- POJ 1195 Mobile Phones
- POJ 1195 Mobile phones
- POJ 1195 Mobile phones
- 再说lv 的同步 (最近的所获真大)
- 表单的通用验证
- 访问 IIS 7.0 SSL站点时报“HTTP 错误 403.16-禁止访问”的解决办法
- HDU/HDOJ 2255 奔小康赚大钱 HDOJ 2008 Summer Exercise(4)- Buffet Dinner
- MSTR创建项目
- poj 1195 mobile phones
- 快速排序之按主元分块新方法(值得一看)
- 数字图像处理中的一些概念
- 安全性测试修复意见总结 .
- myeclipse 乱码的解决
- cvThreshold||cvLine||cvLoadImage,cvCreateImage之灰度
- 差分约束小结(poj1201,poj1716,poj1364,poj3159,poj3169,poj1275)
- sap brute
- 如何在命令行下编译C++程序