zoukankan      html  css  js  c++  java
  • (简单) POJ 2029 Get Many Persimmon Trees,暴力。

    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.
     
      感觉就是暴力大水题。。。
     
    代码如下:
    // ━━━━━━神兽出没━━━━━━
    //      ┏┓       ┏┓
    //     ┏┛┻━━━━━━━┛┻┓
    //     ┃           ┃
    //     ┃     ━     ┃
    //     ████━████   ┃
    //     ┃           ┃
    //     ┃    ┻      ┃
    //     ┃           ┃
    //     ┗━┓       ┏━┛
    //       ┃       ┃
    //       ┃       ┃
    //       ┃       ┗━━━┓
    //       ┃           ┣┓
    //       ┃           ┏┛
    //       ┗┓┓┏━━━━━┳┓┏┛
    //        ┃┫┫     ┃┫┫
    //        ┗┻┛     ┗┻┛
    //
    // ━━━━━━感觉萌萌哒━━━━━━
    
    // Author        : WhyWhy
    // Created Time  : 2015年07月20日 星期一 09时57分41秒
    // File Name     : 2029.cpp
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    
    using namespace std;
    
    int W,H;
    int N;
    int map1[110][110];
    int S,T;
    
    int sum(int x1,int y1,int x2,int y2)
    {
        return map1[x2][y2]-map1[x1-1][y2]-map1[x2][y1-1]+map1[x1-1][y1-1];
    }
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
    
        int a,b;
    
        while(~scanf("%d",&N) && N)
        {
            memset(map1,0,sizeof(map1));
            scanf("%d %d",&W,&H);
    
            for(int i=1;i<=N;++i)
            {
                scanf("%d %d",&a,&b);
                map1[a][b]=1;
            }
    
            scanf("%d %d",&S,&T);
    
            for(int i=1;i<=W;++i)
                for(int j=1;j<=H;++j)
                    map1[i][j]+=map1[i][j-1];
    
            for(int j=1;j<=H;++j)
                for(int i=1;i<=W;++i)
                    map1[i][j]+=map1[i-1][j];
    
            int ans=0;
    
            for(int i=1;i+S-1<=W;++i)
                for(int j=1;j+T-1<=H;++j)
                    ans=max(ans,sum(i,j,i+S-1,j+T-1));
    
            printf("%d
    ",ans);
        }
        
        return 0;
    }
    View Code
  • 相关阅读:
    微软 PowerShell Script Explorer
    MVC, MVP, MVVM比较以及区别(上)
    MVC中使用Unity Ioc Container
    java实现电脑远程控制完整源代码(转)
    强大的Mockito测试框架(转)
    File中操作路径的API(转)
    java如何把char型数据转换成int型数据(转)
    Test class should have exactly one public zero-argument constructor
    tomcat的webappclassloader中一个奇怪的异常信息
    在asp.net mvc中使用PartialView返回部分HTML段
  • 原文地址:https://www.cnblogs.com/whywhy/p/4660659.html
Copyright © 2011-2022 走看看