题意:给出一个h*w的矩形,再给出n个坐标,在这n个坐标种树,再给出一个s*t大小的矩形,问在这个s*t的矩形里面最多能够得到多少棵树

二维的树状数组,求最多能够得到的树的时候,因为h,w都不超过500,直接暴力

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include <cmath>
  5. #include<stack>
  6. #include<vector>
  7. #include<map>
  8. #include<set>
  9. #include<queue>
  10. #include<algorithm>
  11. using namespace std;
  12.  
  13. typedef long long LL;
  14. const int INF = (<<)-;
  15. const int mod=;
  16. const int maxn=;
  17.  
  18. int c[maxn][maxn];
  19.  
  20. int lowbit(int x){ return x & (-x);}
  21.  
  22. int sum(int x,int y){
  23. int ret=;
  24. int y1;
  25. while(x > ){
  26. y1=y;
  27. while(y1 > ){
  28. ret += c[x][y1];y1-=lowbit(y1);
  29. }
  30. x-=lowbit(x);
  31. }
  32. return ret;
  33. }
  34.  
  35. void add(int x,int y,int d){
  36. int y1;
  37. while(x < maxn){
  38. y1=y;
  39. while(y1 < maxn){
  40. c[x][y1] += d;y1+=lowbit(y1);
  41. }
  42. x+=lowbit(x);
  43. }
  44. }
  45.  
  46. int main(){
  47. int n;
  48. while(scanf("%d",&n)!=EOF && n){
  49. memset(c,,sizeof(c));
  50. int w,h;
  51. scanf("%d %d",&w,&h);
  52. while(n--){
  53. int u,v;
  54. scanf("%d %d",&u,&v);
  55. add(v,u,);
  56. }
  57. int x,y;
  58. scanf("%d %d",&x,&y);swap(x,y);
  59.  
  60. int ans=-;
  61. int tmp=;
  62. for(int i=;i <=h;i++){
  63. for(int j=;j<=w;j++){
  64. tmp = sum(i+x-,j+y-)-sum(i-,j+y-)-sum(i+x-,j-)+sum(i-,j-);
  65. ans = max(ans,tmp);
  66. }
  67. }
  68. printf("%d\n",ans);
  69. }
  70. return ;
  71. }

POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】的更多相关文章

  1. POJ2029:Get Many Persimmon Trees(二维树状数组)

    Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...

  2. [poj2155]Matrix(二维树状数组)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 25004   Accepted: 9261 Descripti ...

  3. POJ 2029 Get Many Persimmon Trees (二维树状数组)

    Get Many Persimmon Trees Time Limit:1000MS    Memory Limit:30000KB    64bit IO Format:%I64d & %I ...

  4. POJ 2029 Get Many Persimmon Trees(DP||二维树状数组)

    题目链接 题意 : 给你每个柿子树的位置,给你已知长宽的矩形,让这个矩形包含最多的柿子树.输出数目 思路 :数据不是很大,暴力一下就行,也可以用二维树状数组来做. #include <stdio ...

  5. POJ 2029 Get Many Persimmon Trees (模板题)【二维树状数组】

    <题目链接> 题目大意: 给你一个H*W的矩阵,再告诉你有n个坐标有点,问你一个w*h的小矩阵最多能够包括多少个点. 解题分析:二维树状数组模板题. #include <cstdio ...

  6. POJ 2029 (二维树状数组)题解

    思路: 大力出奇迹,先用二维树状数组存,然后暴力枚举 算某个矩形区域的值的示意图如下,代码在下面慢慢找... 代码: #include<cstdio> #include<map> ...

  7. Get Many Persimmon Trees_枚举&&二维树状数组

    Description Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aiz ...

  8. poj 1195:Mobile phones(二维树状数组,矩阵求和)

    Mobile phones Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 14489   Accepted: 6735 De ...

  9. POJ 2155 Matrix【二维树状数组+YY(区间计数)】

    题目链接:http://poj.org/problem?id=2155 Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissio ...

  10. POJ 2155 Matrix(二维树状数组,绝对具体)

    Matrix Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20599   Accepted: 7673 Descripti ...

随机推荐

  1. 高并发之后端优化(PHP)

    页面静态化 使用模板引擎 可以使用Smarty的缓存机制生成静态HTML缓存文件 $smarty->cachedir=$ROOT·"/cache"://缓存目录 $smart ...

  2. P1634 禽兽的传染病

    题目背景 mxj的启发. 题目描述 禽兽患传染病了.一个禽兽会传染x个禽兽.试问n轮传染后有多少禽兽被传染? 输入输出格式 输入格式: 两个数x和n. 输出格式: 一个数:被传染的禽兽数. 输入输出样 ...

  3. Win7下安装Flash低版本

    我把HKEY_LOCAL_MACHINE\SOFTWARE\Macromedia\FlashPlayer\SafeVersions中高于要装的版本的项目都删了,还是不行. 看了这个帖子后发现,原来64 ...

  4. Unity 脚本挂载位置

    原则:谁的脚本,挂载到谁身上 1,一般场景中会有个GameController脚本,挂在空物体上. 2,我见很多人脚本习惯挂到Camera上,好吧,不知算不算规范.

  5. “肥宅快乐数”-python暴力版

     编写一个函数来判断一个数是不是“快乐数”.一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1.如 ...

  6. Pyhton学习——Day6

    # def test(x) : #形参:不占内存空间,调用函数时传入值,程序完成形参释放内存# # 注释内容# # 代码内容# y = x*2# print(y)# # return# # test( ...

  7. [置顶] Elon Musk (伊隆·马斯克):无限的创想与意志的胜利

    Elon Musk (伊隆·马斯克):无限的创想与意志的胜利 很多人说 Steve Jobs 很伟大,这一点我认同.但是,单纯从创造出的产物而言,Elon Musk 的成就毫无疑问远远超越 Steve ...

  8. HDU 2669 Romantic( 拓欧水 )

    链接:传送门 题意:求解方程 X * a + Y * b = 1 的一组最小非负 X 的解,如果无解输出 "sorry" 思路:裸 exgcd /***************** ...

  9. js追加元素

    直接运行 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...

  10. VUE:class与style强制绑定

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...