poj 2029 Get Many Persimmon Trees

题意:

给出一个矩阵,其中某些格子有树,用给定的一个规模的方框去圈,问最多可以圈到多少树。

思路:

二维树状数组裸题。

代码:

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <algorithm>
 4 using namespace std;
 5 const int N = 105;
 6 int c[N][N];
 7 int w,h;
 8 int lowbit(int x)
 9 {
10     return x&(-x);
11 }
12 void add(int x,int y)
13 {
14     for (int i = x;i <= w;i += lowbit(i)) c[i][y] += 1;
15 }
16 int getsum(int x,int y)
17 {
18     int ans = 0;
19     for (int i = x;i > 0;i -= lowbit(i)) ans += c[i][y];
20     return ans;
21 }
22 int main()
23 {
24     int n;
25     while (scanf("%d",&n) != EOF && n)
26     {
27         scanf("%d%d",&w,&h);
28         memset(c,0,sizeof(c));
29         for (int i = 0;i < n;i++)
30         {
31             int x,y;
32             scanf("%d%d",&x,&y);
33             add(x,y);
34         }
35         int s,t;
36         scanf("%d%d",&s,&t);
37         int ans = 0;
38         for (int i = s;i <= w;i++)
39         {
40             for (int j = t;j <= h;j++)
41             {
42                 int tmp = 0;
43                 for (int k = j - t + 1;k <= j;k++)
44                 {
45                     tmp += getsum(i,k) - getsum(i-s,k);
46                 }
47                 ans = max(ans,tmp);
48             }
49         }
50         printf("%d\n",ans);
51     }    
52     return 0;
53 }

 

posted @ 2018-05-22 18:36  qrfkickit  阅读(119)  评论(0编辑  收藏  举报