POJ 2029
来源:互联网 发布:精通python网络爬虫pdf 编辑:程序博客网 时间:2024/05/29 18:53
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////分析:
二位树状数组对矩阵进行矩形范围内的统计,类比于一维树状数组中统计某个区间内的和:sum(i)-sum(j);在二维树状数组中要减两个部分再加一个重叠部分:sum(i+t,j+s)-sum(i,j+s)-sum(i+t,j)+sum(i,j)。
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int C[505][505];int lowbit(int x){ return x&-x;}void update(int i,int j,int W,int H){ int x=i; int y=j; while(x<=W){ y=j; while(y<=H){ C[x][y]++; y+=lowbit(y); } x+=lowbit(x); }}int sum(int i,int j){ if(!(i&&j))return 0; int x=i; int y=j; int ans=0; while(x){ y=j; while(y){ ans+=C[x][y]; y-=lowbit(y); } x-=lowbit(x); } return ans;}int main(){ // freopen("in.txt","r",stdin); int n,W,H,S,T; while(~scanf("%d",&n)&&n){ memset(C,0,sizeof(C)); scanf("%d%d",&W,&H); for(int i=0;i!=n;++i){ int x,y; scanf("%d%d",&x,&y); update(x,y,W,H); } scanf("%d%d",&S,&T); int ans;ans=0; for(int i=S;i<=W;++i){ for(int j=T;j<=H;++j){ int temp; temp=sum(i,j)+sum(i-S,j-T)-sum(i-S,j)-sum(i,j-T); if(temp>ans)ans=temp; } } // for(int i=1;i<=W;++i){for(int j=1;j<=H;++j)printf("%d ",sum(i,j));printf("\n");} printf("%d\n",ans); } return 0;}
0 0
- POJ 2029
- poj 2029
- poj 2029
- poj-2029
- POJ 2029
- POJ 2029 预处理
- POJ 2029 DP || 暴力
- POJ 2029 水DP
- POJ 2029 递推
- poj 2029 树状数组
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- Android屏幕适配全攻略(最权威的官方适配指导)
- 使用Unity3D的50个技巧:Unity3D最佳实践(下)
- 解决DM8168上电自动启动,不需要手动登陆root
- 基于 SurfaceView 详解 android 幸运大转盘,附带实例app
- 补丁比较工具Darun Grim使用
- POJ 2029
- HDU 5389 Zero Escape(DP + 滚动数组)
- 华为OJ平台试题 —— 字符串:名字的漂亮度
- Hadoop 原理总结
- 初识Javascript的面向对象
- POJ3903 Stock Exchange
- POJ 1163 The Triangle(三种搜索方式)
- hdu 2602 Bone Collector(01背包)
- libpcap动态链接库在linux下使用以及接口函数