POJ 2029 Get Many persimmon Trees (two-dimensional tree-like array)

Source: Internet
Author: User

Get many persimmon TreesTime Limit:MS Memory Limit:30000KB 64bit IO Format:%i64d &A mp %i64u SubmitStatusPracticePOJ 2029

Description

Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th cent Ury. In order to reward him for he meritorious career in education, Katanobu Matsudaira, the Lord of the domain of Aizu, had D Ecided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate is strictly specified by the Lord, he is allowed to choose any Locati On for the estate in the field. Inside the field which had also a rectangular shape, many Japanese persimmon trees, whose fruit was one of the famous prod Ucts of the Aizu region known as ' Mishirazu Persimmon ', were planted. Since Persimmon was Hayashi's favorite fruit, he wanted to has as many persimmon trees as possible in the estate given by The Lord.
For example, with Figure 1, the entire field was a rectangular grid whose width and height are ten and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate is 4 and 3 respectively, the area surrounded by the solid line contains T He most persimmon trees. Similarly, if the estate ' s width is 6 and its height are 4, the area surrounded by the dashed line have the most, and if the Estate's width and height is 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon tr Ees. Note that the width and height cannot is swapped; The sizes 4 by 3 and 3 by 4 is different, as shown in Figure 1.

Figure 1:examples of Rectangular Estates
Your task is to find the estate of a given size (width and height), that contains the largest number of persimmon trees.

Input

The input consists of multiple data sets. Each data set was given in the following format.

N
W H
X1 Y1
X2 y2
...
XN YN
S T

N is the number of persimmon trees, which are a positive integer less than 500. W and H are the width and the height of the entire field respectively. You can assume that both W and H is positive integers whose values is less than 100. For each I (1 <= i <= N), Xi and Yi is coordinates of the i-th persimmon tree in the grid. Note The origin of each coordinate is 1. You can assume that 1 <= XI <= W and 1 <= yi <= H, and no both trees have the same positions. But you should isn't assume that the persimmon trees is sorted in some order according to their positions. Lastly, S and T is positive integers of the width and height respectively of the estate given by the Lord. You can also assume that 1 <= S <= W and 1 <= T <= H.

The end of the input is indicated by a line that solely contains a zero.

Output

For each data set, you is requested to print one line containing the maximum possible number of persimmon trees that can is included in an estate of the given size.

Sample Input

1610 82 22 52 73 33 84 24 54 86 46 77 57 88 18 49 610 34 386 41 22 12 43 44 25 36 16 23 20

Sample Output

43



Roughly test instructions: The King's territory has w*h points, of which there are trees at n points, and now the most agreeable circle in the territory (of course, less than) is the size of a rectangle of s*t, how many trees can be in a circle?



Problem-solving ideas: The lifting point, the two-dimensional tree-like array solution.


When lifting points, be careful to start with the rows and columns from S and T. Until W and H.

When using a two-dimensional tree array. Note that when update () is updated each time, c[] adds 1.



AC Code:

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn = 102;int N, W, H, S, T;int c[maxn][maxn];int lowbit (int x) {return x& (-X);} void update (int x,int y) {for (int i=x, i<maxn; i+=lowbit (i)) for (int j=y; j<maxn; j+=lowbit (j)) C[i][j] + +;} Long long sum (int x, int y) {long Long ans = 0;for (int i=x; i>0; i-=lowbit (i)) for (int j=y; j>0; j-=lowbit (J)) ans + = C I [J];return ans;} int main () {#ifndef online_judgefreopen ("In.txt", "R", stdin), #endifint x, Y;while (~scanf ("%d", &n) && N) { scanf ("%d%d", &w, &h), memset (C,0,sizeof (c)), for (int i=1; i<=n; i++) {scanf ("%d%d", &x, &y); Update (x , y);} scanf ("%d%d", &s, &t); long long ans = 0;      for (int i=s; i<=w; i++)//enumeration start for (int j=t; j<=h; j + +) ans = max (ans, sum (i, J)-Sum (I-s, J)-Sum (i, j-t) + sum    (I-s, j-t)); Tree-like array for area and printf ("%lld\n", ans);} return 0;}


POJ 2029 Get Many persimmon Trees (two-dimensional tree-like array)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.