poj 2029 Get Many Persimmon Trees
来源:互联网 发布:广州聚友网络客服电话 编辑:程序博客网 时间:2024/05/20 07:18
点击打开poj 2029
思路: 简单的二维树状数组
分析:
1 题目给定一个人h*w的矩阵,给定n个点表示该点上面有柿子树,求给定一个t*s的矩阵的最多的柿子树的个数
2 简单的二维树状数组,加入一个点的时候更新树状数组
3 题目的范围最大为100,很明显就是要暴力枚举起点,然后求最大值即可
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int MAXN = 110;int n , w , h;int treeNum[MAXN][MAXN];int lowbit(int x){ return x&(-x);}void add(int x , int y , int val){ for(int i = x ; i < MAXN ; i += lowbit(i)) for(int j = y ; j < MAXN ; j += lowbit(j)) treeNum[i][j] += val;}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 += treeNum[i][j]; return sum;}int solve(int x , int y){ int ans = 0; for(int i = 1 ; i <= h ; i++){ for(int j = 1 ; j <= w ; j++){ int sum = getSum(i+x-1 , j+y-1); sum -= getSum(i-1 , j+y-1); sum -= getSum(i+x-1 , j-1); sum += getSum(i-1 , j-1); ans = max(ans , sum); } } return ans;}int main(){ int x , y; while(scanf("%d" , &n) && n){ scanf("%d%d" , &w , &h); memset(treeNum , 0 , sizeof(treeNum)); for(int i = 0 ; i < n ; i++){ scanf("%d%d" , &x , &y); add(y , x , 1); } scanf("%d%d" , &x , &y); printf("%d\n" , solve(y , x)); } return 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)
- JS 动态创建表格
- SQLSERVER 自增列
- 多校第七场
- c++ 找出序列中出现得最频繁的值
- linux likely and unlikely解析
- poj 2029 Get Many Persimmon Trees
- Tempter of the Bone_hdu_1010(深搜).java
- 小Q系列故事——大笨钟
- expandlistview 分组+浮动条
- 图像常用名词解释
- HDU-1010-Tempter of the Bone
- POJ 1273 Drainage Ditches 题解与分析<网络流DINIC>
- windows文件命名规范
- Cocos2d-x Touch事件处理机制