poj 2029 && zoj 1716 Get Many Persimmon Trees
2011-08-11 09:43
441 查看
树状数组的题目,暴力水过。但是,我表示对树状数组理解的还不是很清楚。尤其是在更新值的时候,为啥有时候就要再原来的值上加1,有时候就不加。很多的东西都需要仔细的体会,真是..TT...不说了!
#include<stdio.h> #include<iostream> #include<string.h> using namespace std; #define N 130 int c ; int n,m; int lowbit(int x) { return x&(-x); } void Updata(int x,int y) { for(int i=x;i<=N;i+=lowbit(i)) { for(int j=y;j<=N;j+=lowbit(j)) { c[i][j]++; } } } int Getsum(int x,int y) { int sum=0; for(int i=x;i>0;i-=lowbit(i)) { for(int j=y;j>0;j-=lowbit(j)) { sum+=c[i][j]; } } return sum; } int main() { int cnt; int x,y,x1,y1; while(scanf("%d",&cnt)&&cnt) { scanf("%d%d",&n,&m); memset(c,0,sizeof(c)); while(cnt--) { scanf("%d%d",&x,&y); Updata(x,y); } scanf("%d%d",&x1,&y1); int max=0; for(int i=x1;i<=n;i++) { for(int j=y1;j<=m;j++) { int ans=Getsum(i,j)-Getsum(i-x1,j)-Getsum(i,j-y1)+Getsum(i-x1,j-y1); if(max<ans)max=ans; } } printf("%d\n",max); } return 0; }
相关文章推荐
- POJ 2029 && ZOJ 1716 Get Many Persimmon Trees
- POJ 2029 && ZOJ 1716 Get Many Persimmon Trees
- zoj 1716 || poj 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees 二维树状数组
- poj 2029 Get Many Persimmon Trees
- poj-2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- (简单) POJ 2029 Get Many Persimmon Trees,暴力。
- POJ 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees 二维线段树 单点更新 区间求和
- poj 2029 Get Many Persimmon Trees (dp)
- POJ-2029 Get Many Persimmon Trees 树状数组
- POJ 2029 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees
- zoj1716 Get Many Persimmon Trees
- POJ 2029 Get Many Persimmon Trees(二维树状数组)
- 【poj 2029】Get Many Persimmon Trees 题意&题解
- POJ2029——Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees 【二维树状数组】