zoukankan      html  css  js  c++  java
  • POJ2029 Get Many Persimmon Trees

     

     

    Time Limit: 1000MS   Memory Limit: 30000K
    Total Submissions: 4100   Accepted: 2685

    Description

    Seiji Hayashi had been a professor of the Nisshinkan Samurai School in the domain of Aizu for a long time in the 18th century. In order to reward him for his meritorious career in education, Katanobu Matsudaira, the lord of the domain of Aizu, had decided to grant him a rectangular estate within a large field in the Aizu Basin. Although the size (width and height) of the estate was strictly specified by the lord, he was allowed to choose any location 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 products of the Aizu region known as 'Mishirazu Persimmon', were planted. Since persimmon was Hayashi's favorite fruit, he wanted to have as many persimmon trees as possible in the estate given by the lord.
    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

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

    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

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

    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
    ",ans);
    58     }
    59     return 0;
    60 }
  • 相关阅读:
    没有什么,开发ASP.NET时随便写写,想到什么写什么
    MS SQL Server带有时间的记录怎样查询
    给RadioButtonList绑定Selected的值
    在GridView控件内文本框实现TextChanged事件
    MS SQL Server递归查询
    ASP.NET MVC使用jQuery无刷新上传
    MySQL 慢查询操作梳理
    ubuntu系统下防火墙简单使用
    crontab日常使用梳理
    ubuntu下nginx+php5的部署
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5704599.html
Copyright © 2011-2022 走看看