Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 4100 | Accepted: 2685 |
Description
For example, in Figure 1, the entire field is a rectangular grid whose width and height are 10 and 8 respectively. Each asterisk (*) represents a place of a persimmon tree. If the specified width and height of the estate are 4 and 3 respectively, the area surrounded by the solid line contains the most persimmon trees. Similarly, if the estate's width is 6 and its height is 4, the area surrounded by the dashed line has the most, and if the estate's width and height are 3 and 4 respectively, the area surrounded by the dotted line contains the most persimmon trees. Note that the width and height cannot be swapped; the sizes 4 by 3 and 3 by 4 are 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
N
W H
x1 y1
x2 y2
...
xN yN
S T
N is the number of persimmon trees, which is 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 are positive integers whose values are less than 100. For each i (1 <= i <= N), xi and yi are coordinates of the i-th persimmon tree in the grid. Note that the origin of each coordinate is 1. You can assume that 1 <= xi <= W and 1 <= yi <= H, and no two trees have the same positions. But you should not assume that the persimmon trees are sorted in some order according to their positions. Lastly, S and T are 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
Sample Input
16
10 8
2 2
2 5
2 7
3 3
3 8
4 2
4 5
4 8
6 4
6 7
7 5
7 8
8 1
8 4
9 6
10 3
4 3
8
6 4
1 2
2 1
2 4
3 4
4 2
5 3
6 1
6 2
3 2
0
Sample Output
4
3
Source
题外话:
背景故事挺神奇,以至于我专门去搜了一下“日新馆”,好像挺神奇的……
简介先放在这儿,无聊的时候来翻译练练手233333
————————————————
会津における教育のはじまりは、日新館創設より更にさかのぼること寛文4(1664)年、日本で初めて民間により創設した庶民のための学問所といわれる「稽古堂(けいこどう)」とされています。これに対し、会津藩初代藩主 保科正之は税金を免除し、大いに奨励しました。
江戸時代も200年が過ぎ、太平の世になってくると、今までの風習が変化し武士の気もゆるみ始め、道徳の退廃も顕著になってきました。天明 2(1782)年から数年間続いた天明の大飢饉をはさんで、会津藩内でも様々な問題が出てきます。その諸問題を解決すべく、5代藩主 松平容頌の時、家老 田中玄宰は藩政の改革をするよう進言し、その中心に「教育の振興」をあげ、このことが日新館創設のきっかけとなりました。日新館の建設は、それは大変な作業でした。着工となってからは大司成 (現在で言えば文部科学大臣)、小司成、さらには日新館の教授、生徒たちまでもが、草鞋をはき協力しました。
多額の建設資金は、呉服商を営む大商人、須田新九郎が大半を負担しました。
そして享和3(1803)年、五ヶ年の歳月を費やし、文武の両教科を教授する総合学校「日新館」が完成しました。
————————————————
正文:
数据范围比较小,所以可以暴力枚举区间左上角坐标,统计区间内树的个数,求最大值。(看评论说暴力可以过)
为了让题解显得更高端,这里使用了二位树状数组来查询区间值。
1 /**/ 2 #include<iostream> 3 #include<cstdio> 4 #include<cmath> 5 #include<cstring> 6 #include<algorithm> 7 using namespace std; 8 const int mxn=200; 9 int mp[mxn][mxn]; 10 int t[mxn][mxn]; 11 int n,a,b; 12 inline int lowbit(int x){return x&-x;} 13 void add(int x,int y,int w){ 14 while(x<mxn){ 15 int tmp=y; 16 while(tmp<mxn){ 17 t[x][tmp]+=w; 18 tmp+=lowbit(tmp); 19 } 20 x+=lowbit(x); 21 } 22 return; 23 } 24 int sum(int x,int y){ 25 int res=0; 26 while(x){ 27 int tmp=y; 28 while(tmp){ 29 res+=t[x][tmp]; 30 tmp-=lowbit(tmp); 31 } 32 x-=lowbit(x); 33 } 34 return res; 35 } 36 int query(int x,int y,int qx,int qy){ 37 int rx=x+qx-1,ry=y+qy-1; 38 return sum(rx,ry)-sum(x-1,ry)-sum(rx,y-1)+sum(x-1,y-1); 39 } 40 int main(){ 41 while(scanf("%d",&n) && n){ 42 memset(mp,0,sizeof mp); 43 memset(t,0,sizeof t); 44 int i,j; 45 scanf("%d%d",&a,&b); 46 int x,y; 47 for(i=1;i<=n;i++){ 48 scanf("%d%d",&x,&y); 49 add(x,y,1); 50 } 51 scanf("%d%d",&x,&y); 52 int ans=0; 53 for(i=1;i<=a-x+1;i++) 54 for(j=1;j<=b-y+1;j++){ 55 ans=max(ans,query(i,j,x,y)); 56 } 57 printf("%d\n",ans); 58 } 59 return 0; 60 }