poj 2029 Get Many Persimmon Trees
来源:互联网 发布:sun.java 编辑:程序博客网 时间:2024/06/05 05:48
题意:美丽的夜晚有许多的星星,每个星星都有自己的坐标,你有一个长宽确定的窗户,问如何安置窗户可以看到最多的星星的数量,
思路:之前只学了一维的树状数组,想这个题的时候竟然自己yy出了二维的用法,这里我将每一竖行用树状数组储存星星的个数,如a[i][j]代表第i列前1~j行的星星数量,形成一个二维的树状数组,计算最大的星星数量时,枚举窗户位置,利用树状数组的查询功能快速计算出可以看到星星的数量,
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int a[120][120];int n,w,h,s,t;int low(int x){return x&(-x);}int que(int x,int y){int tmp=y;int sum=0;while(tmp>0){sum+=a[x][tmp];tmp-=low(tmp);}return sum;}int add(int x,int y){int tmp=y;while(tmp<110){a[x][tmp]+=1;tmp+=low(tmp);}return 1;}int main(){freopen("in.txt","r",stdin);while(scanf("%d",&n)!=EOF&&n){ memset(a,0,sizeof(a));scanf("%d%d",&w,&h);int x,y;for(int i=0;i<n;i++){scanf("%d%d",&x,&y);add(x,y);}scanf("%d%d",&s,&t);int ans=0,sum=0;for(int i=1;i+s-1<=w;i++){for(int j=1;j+t-1<=h;j++){sum=0;for(int k=i;k<=i+s-1;k++){sum+=(que(k,j+t-1)-que(k,j-1));}ans=max(ans,sum);}}printf("%d\n",ans);}}
0 0
- 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-预处理
- 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
- POJ 2029 Get Many Persimmon Trees
- poj 2029 Get Many Persimmon Trees
- poj- 2029 -Get Many Persimmon Trees (DP)
- [leetcode] Max Points on a Line 判断最多有多少个点在同一条直线上
- Android消息队列图片记录
- common lisp 中宏定义时不能使用#'? 形式的函数作为参数
- 3.建造者模式(设计模式笔记)
- HDU 5389 Zero Escape (MUT#8 dp优化)
- poj 2029 Get Many Persimmon Trees
- 特征提取代码总结
- org.apache.commons.lang3功能示例
- c 语言 删除字符串中尾部的空格符 制表符与换行符
- 原子战舰STM32——定时器捕获中断库函数程序中中断处理函数说明
- 零基础学python-2.19 定义函数、调用函数与默认参数
- Java中Properties类的操作
- 利用ssh登录服务器
- wxPython Cookbook (Chatper1)part 2