zoukankan      html  css  js  c++  java
  • POJ 2029 Get Many Persimmon Trees 【 二维树状数组 】

    题意:给出一个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 = (1<<30)-1;
    15 const int mod=1000000007;
    16 const int maxn=1005;
    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=0;
    24     int y1;
    25     while(x > 0){
    26         y1=y;
    27         while(y1 > 0){
    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,0,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,1);
    56         }
    57         int x,y;
    58         scanf("%d %d",&x,&y);swap(x,y);
    59         
    60         int ans=-1;
    61         int tmp=0;
    62         for(int i=1;i <=h;i++){
    63             for(int j=1;j<=w;j++){
    64                 tmp = sum(i+x-1,j+y-1)-sum(i-1,j+y-1)-sum(i+x-1,j-1)+sum(i-1,j-1);
    65                 ans = max(ans,tmp);
    66             }
    67         }
    68         printf("%d
    ",ans);
    69     }
    70     return 0;
    71 }
    View Code
  • 相关阅读:
    手机精准定位,看好你的男朋友
    顶级分享,三端看片的日子来了
    这样的声音谁受的了呀
    白嫖vip电台,资源随意听
    老板止步!这里全是小姐姐
    粉丝福利。无视墙 来看看全世界的网站吧
    利用自己的服务器搭建专属私有云盘&博客园搬家
    Photoshop 2020 安装教程
    TensorFlow基础——常用函数(一)
    Scala基本语法入门
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4593228.html
Copyright © 2011-2022 走看看