zoukankan      html  css  js  c++  java
  • Codeforces Gym 100002 C "Cricket Field" 暴力

    "Cricket Field"

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/gym/100002

    Description

    Once upon a time there was a greedy King who ordered his chief Architect to build a field for royal cricket inside his park. The King was so greedy, that he would not listen to his Architect's proposals to build a field right in the park center with pleasant patterns of trees specially planted around and beautiful walks inside tree alleys for spectators. Instead, he ordered neither to cut nor to plant even a single tree in his park, but demanded to build the largest possible cricket field for his pleasure. If the Kind finds that the Architect has dared to touch even a single tree in his park or designed a smaller field that it was possible, then the Architect will loose his head. Moreover, he demanded his Architect to introduce at once a plan of the field with its exact location and size.

    Your task is to help poor Architect to save his head, by writing a program that will find the maximum possible size of the cricket field and its location inside the park to satisfy King's requirements.

    The task is somewhat simplified by the fact, that King's park has a rectangular shape and is situated on a flat ground. Moreover, park's borders are perfectly aligned with North-South and East-West lines. At the same time, royal cricket is always played on a square field that is also aligned with North-South and East-West lines. Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of every tree. This coordinate system is, of course, aligned with North-South and East-West lines. Southwestern corner of the park has coordinates (0, 0) and Northeastern corner of the part has coordinates (W, H), where W and H are the park width and height in feet respectively.

    For this task, you may neglect the diameter of the trees. Trees cannot be inside the cricket field, but may be situated on its side. The cricket field may also touch park's border, but shall not lie outside the park.

    Input

    The first line of the input file contains three integer numbers N, W, and H, separated by spaces. N (0 ≤ N ≤ 100) is the number of trees in the park. W and H (1 ≤ W, H ≤ 10000) are the park width and height in feet respectively.

    Next N lines describe coordinates of trees in the park. Each line contains two integer numbers Xi and Yi separated by a space (0 ≤ Xi ≤ W, 0 ≤ Yi ≤ H) that represent coordinates of ith tree. All trees are located at different coordinates.

    Output

    Write to the output file a single line with three integer numbers P, Q, and L separated by spaces, where (P, Q) are coordinates of the cricket field Southwestern corner, and L is a length of its sides. If there are multiple possible field locations with a maximum size, then output any one.

    Sample Input

    7 10 7

    3 2

    4 2

    7 0

    7 3

    4 5

    2 4

    1 7

    Sample Output

    4 3 4

    HINT

     

    题意

    给你个nm的区域,问你最大的内部没有树的正方形有多大(边界上可以有树

    题解:

    读入Y轴之后,暴力枚举Y轴

    然后统计在这个区域的正方形最大是多少

    代码:

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    #include <vector>
    #include <stack>
    #include <map>
    #include <set>
    #include <queue>
    #include <iomanip>
    #include <string>
    #include <ctime>
    #include <list>
    #include <bitset>
    typedef unsigned char byte;
    #define pb push_back
    #define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
    #define local freopen("in.txt","r",stdin)
    #define pi acos(-1)
    
    using namespace std;
    const int maxn = 1e2 + 15;
    int n , w , h ,ansx = 0 , ansy = 0 , ans = 0;
    struct point
    {
        int x , y ;
        friend bool operator < (const point & a,const point & b)
        {
            return a.x < b.x || (a.x == b.x && a.y<b.y);
        }
    };
    
    point p[maxn];
    vector<int>Line;
    
    void initiation()
    {
        scanf("%d%d%d",&n,&w,&h);
        Line.push_back(0);
        Line.push_back(h);
        for(int i = 0 ; i < n ; ++ i)
        {
            scanf("%d%d",&p[i].x,&p[i].y);
            Line.push_back(p[i].y);
        }
    }
    
    
    void solve()
    {
        sort(Line.begin() , Line.end());
        int c = unique(Line.begin() , Line.end()) - Line.begin();
        sort(p , p + n);
        for(int i = 0 ; i < c ; ++ i)
        {
            for(int j = i + 1 ; j < c ; ++ j)
            {
                int L = Line[i];
                int R = Line[j];
                int h = R-L;
                int pre = 0;
                for(int k = 0 ; k < n ; ++ k)
                {
                    if(p[k].y >= R || p[k].y <= L) continue;
                    int tx = p[k].x - pre;
                    int newans = min( tx , h );
                    if(newans > ans)
                    {
                        ans = newans;
                        ansx = pre;
                        ansy = L;
                    }
                    pre = p[k].x;
                }
                int tx = w - pre;
                int newans = min( tx , h );
                if(newans > ans)
                {
                    ans = newans;
                    ansx = pre;
                    ansy = L;
                }
            }
        }
        printf("%d %d %d
    ",ansx,ansy,ans);
    }
    
    
    int main(int argc,char *argv[])
    {
        freopen("cricket.in","r",stdin);
        freopen("cricket.out","w",stdout);
        initiation();
        if(n == 0) printf("0 0 %d
    ",min(w,h));
        else solve();
        return 0;
    }
  • 相关阅读:
    转载-如何高效的学习技术
    Lc176-第二高的薪水
    Lc4-寻找两个有序数组的中位数
    Lc175-组合两个表
    Lc3-无重复字符的最长子串
    Lc2-俩数相加
    Lc1- 两数之和
    jpa-子查詢
    20191225页面样式
    leetcode二刷结束
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4782170.html
Copyright © 2011-2022 走看看