• The E-pang Palace


    E-pang Palace was built in Qin dynasty by Emperor Qin Shihuang in Xianyang, Shanxi Province. It
    was the largest palace ever built by human. It was so large and so magnificent that after many years
    of construction, it still was not completed. Building the great wall, E-pang Palace and Qin Shihuang’s
    tomb cost so much labor and human lives that people rose to fight against Qin Shihuang’s regime.
    Xiang Yu and Liu Bang were two rebel leaders at that time. Liu Bang captured Xianyang — the
    capital of Qin. Xiang Yu was very angry about this, and he commanded his army to march to Xianyang.
    Xiang Yu was the bravest and the strongest warrior at that time, and his army was much more than
    Liu Bang’s. So Liu Bang was frighten and retreated from Xianyang, leaving all treasures in the grand
    E-pang Palace untouched. When Xiang Yu took Xianyang, he burned E-pang Palce. The fire lasted
    for more than three months, renouncing the end of Qin dynasty.
    Several years later, Liu Bang defeated Xiangyu and became the first emperor of Han dynasty. He
    went back to E-pang Palace but saw only some pillars left. Zhang Liang and Xiao He were Liu Bang’s
    two most important ministers, so Liu Bang wanted to give them some awards. Liu Bang told them:
    “You guys can make two rectangular fences in E-pang Palace, then the land inside the fences will
    belongs to you. But the corners of the rectangles must be the pillars left on the ground, and two fences
    can’t cross or touch each other.”
    To simplify the problem, E-pang Palace can be consider as a plane, and pillars can be considered as
    points on the plane. The fences you make are rectangles, and you MUST make two rectangles. Please
    note that the rectangles you make must be parallel to the coordinate axes.
    The figures below shows 3 situations which are not qualified (Thick dots stands for pillars):
    Zhang Liang and Xiao He wanted the total area of their land in E-pang Palace to be maximum.
    Please bring your computer and go back to Han dynasty to help them so that you may change the
    history.

    Input

    There are no more than 15 test case.
    For each test case: The first line is an integer N, meaning that there are N pillars left in E-pang
    Palace(4 ≤ N ≤ 30). Then N lines follow. Each line contains two integers x and y (0 ≤ x, y ≤ 200),
    indicating a pillar’s coordinate. No two pillars has the same coordinate.
    The input ends by N = 0.

    Output

    For each test case, print the maximum total area of land Zhang Liang and Xiao He could get. If it was
    impossible for them to build two qualified fences, print ‘imp’.
    Sample Input
    8
    0 0
    1 0
    0 1
    1 1
    0 2
    1 2
    0 3
    1 3
    8
    0 0
    2 0
    0 2
    2 2
    1 2
    3 2
    1 3
    3 3
    0
    Sample Output
    2
    imp

    #include<cstdio>
    #include<cstring>
    #include<stack>
    #include<queue>
    #include<cmath>
    #include<cstdlib>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int oo = 1e9+7;
    const int maxn = 888;
    typedef long long LL;
    int vis[maxn][maxn], n;
    struct da
    {
        int x, y;
        bool operator < ( const da & a)const
        {
            if(x == a.x) return y < a.y;
            return x < a.x;
        }
    } as[maxn];
    struct node
    {
        da a, b;
        int area;
    } rec[maxn*10];
    int judge(int xx, int yy)/**< 返回1表示2个矩阵没有交集  2表示第一个包含第2个*/
    {
        if(rec[xx].b.x < rec[yy].a.x) return 1;
    
        if(rec[xx].b.y < rec[yy].a.y) return 1;
    
        if(rec[xx].a.x > rec[yy].b.x) return 1;
    
        if(rec[xx].a.y > rec[yy].b.y) return 1;
    
        if(rec[xx].a.x < rec[yy].a.x && rec[xx].a.y < rec[yy].a.y)
            if(rec[xx].b.x > rec[yy].b.x && rec[xx].b.y > rec[yy].b.y)
                return 2;
    
        return 0;
    }
    int main()
    {
        int i, ans, j, k;
        while(scanf("%d", &n), n)
        {
            memset(vis, 0, sizeof(vis));
            k = 0;
            for(i = 0; i < n; i++)
            {
                scanf("%d %d", &as[i].x, &as[i].y);
                vis[as[i].x][as[i].y] = 1;
            }
    
            sort(as, as+n);/**< 按坐标升序排列*/
    
            for(i = 0; i < n; i++)
            {
                for(j = i+1; j < n; j++)
                {
                    /**< 枚举矩形的坐下方的点和右上方的点并判断左上方的点和右下方的点是否存在*/
                    if(as[i].x<as[j].x && as[i].y<as[j].y && vis[as[i].x][as[j].y] && vis[as[j].x][as[i].y])
                    {
                        rec[k].a.x = as[i].x;
                        rec[k].a.y = as[i].y;
                        rec[k].b.x = as[j].x;
                        rec[k].b.y = as[j].y;
                        rec[k++].area = (as[j].x - as[i].x) * (as[j].y - as[i].y);
                    }
                }
            }
            ans = -oo;
            for(i = 0; i < k; i++)
            {
                for(j = 0; j < k; j++)
                {
                    
                    if(judge(i, j) == 1)
                        ans = max(ans, rec[i].area+rec[j].area);
                        
                    else if(judge(i, j) == 2)
                        ans = max(ans, rec[i].area);
                }
            }
            
            if(ans != -oo)
                printf("%d
    ", ans);
            else puts("imp");
        }
        return 0;
    }
    

      

  • 相关阅读:
    React学习笔记
    士兵杀敌(一)
    网络爬虫Java实现抓取网页内容
    德莱联盟
    计算球体积
    在页面上 获取键盘事件
    一起玩转mysql
    腾讯云 做出的 不错的 动画 chrome小插件
    jquery MD5
    json to xml
  • 原文地址:https://www.cnblogs.com/PersistFaith/p/4859250.html
Copyright © 2020-2023  润新知