POJ 2029 Get Many Persimmon Trees(二维树状数组)
2012-08-11 22:56
302 查看
超级传送门:http://poj.org/problem?id=2029
题意:一块W*H的矩形区域,每一小块可能有柿子树,让你用一个S*T的矩形选择,问最多能选中几棵柿子树。(注意S和T不能倒置,题目给你3 5和5 3是不一样的做法)。
分析:典型的二维树状数组,枚举矩形起点,求和,取最大值,注意边界。
代码:
题意:一块W*H的矩形区域,每一小块可能有柿子树,让你用一个S*T的矩形选择,问最多能选中几棵柿子树。(注意S和T不能倒置,题目给你3 5和5 3是不一样的做法)。
分析:典型的二维树状数组,枚举矩形起点,求和,取最大值,注意边界。
代码:
#include<cstdio> #include<cstring> using namespace std; const int maxn = 505; int n,w,h; int c[maxn][maxn]; int lowbit(int t) { return t & -t; } int getsum(int x,int y) { int ret = 0; for (int i=x;i>=1;i-=lowbit(i)) { for (int j=y;j>=1;j-=lowbit(j)) { ret += c[i][j]; } } return ret; } void update(int x,int y,int val) { for (int i=x;i<=w;i+=lowbit(i)) { for (int j=y;j<=h;j+=lowbit(j)) { c[i][j] += val; } } } int main () { #ifndef ONLINE_JUDGE freopen("1.txt","r",stdin); #endif int s,t,x,y; while (scanf("%d",&n)>0 && n) { memset(c,0,sizeof(c)); scanf("%d%d",&w,&h); for (int i=1;i<=n;i++) { scanf("%d%d",&x,&y); update(x,y,1); } scanf("%d%d",&s,&t); int max = 0; for (int i=s;i<=w;i++) { for (int j=t;j<=h;j++) { int ans = getsum(i,j)-getsum(i-s,j)-getsum(i,j-t)+getsum(i-s,j-t); max = max>ans?max:ans; } } printf("%d\n",max); } return 0; }
相关文章推荐
- 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(二维树状数组)
- POJ 2029 Get Many Persimmon Trees (二维树状数组)
- poj 2029 Get Many Persimmon Trees 二维树状数组
- POJ 2029 Get Many PersimmonTrees(二维树状数组or递推)
- POJ 2029 Get Many Persimmon Trees (二维树状数组 or DP)
- (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(二维BIT)
- POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】
- poj 2029 Get Many Persimmon Trees 【二维树状数组】
- poj 2029 Get Many Persimmon Trees 二维树状数组
- POJ2029:Get Many Persimmon Trees(二维树状数组)
- POJ_2029_GetManyPersimmonTrees
- poj 2029 Get Many Persimmon Trees