poj 2029 Get Many Persimmon Trees 【二维树状数组】

来源:互联网 发布:stc8 串口发送数据 编辑:程序博客网 时间:2024/05/16 01:09

题目链接:poj 2029 Get Many Persimmon Trees

题意:在WH的平面上有N棵树,问你用ST尺寸最多可以括起多少棵树。

暴力枚举右端点。

AC代码:

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <algorithm>#include <vector>#include <queue>#include <map>#include <stack>#define PI acos(-1.0)#define CLR(a, b) memset(a, (b), sizeof(a))#define fi first#define se second#define ll o<<1#define rr o<<1|1using namespace std;typedef long long LL;typedef pair<int, int> pii;const int MAXN = 500 + 10;const int pN = 1e6;// <= 10^7const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;void add(LL &x, LL y) { x += y; x %= MOD; }int C[MAXN][MAXN];int H, W;int lowbit(int x) {    return x & (-x);}void add(int x, int y, int d) {    while(x <= W) {        int sy = y;        while(sy <= H) {            C[x][sy] += d;            sy += lowbit(sy);        }        x += lowbit(x);    }}int Sum(int x, int y) {    int s = 0;    while(x > 0) {        int sy = y;        while(sy > 0) {            s += C[x][sy];            sy -= lowbit(sy);        }        x -= lowbit(x);    }    return s;}int S, T;int Get(int x, int y) {    int x1 = max(1, x - S + 1), y1 = max(1, y - T + 1);    return Sum(x, y) + Sum(x1-1, y1-1) - Sum(x, y1-1) - Sum(x1-1, y);}int main(){    int N;    while(scanf("%d", &N), N)    {        CLR(C, 0);        scanf("%d%d", &W, &H);        while(N--) {            int x, y;            scanf("%d%d", &x, &y);            add(x, y, 1);        }        scanf("%d%d", &S, &T);        int ans = 0;        for(int i = S; i <= W; i++) {            for(int j = T; j <= H; j++) {                ans = max(ans, Get(i, j));            }        }        printf("%d\n", ans);    }    return 0;}
0 0