• UVALive 7070 The E-pang Palace 暴力


    The E-pang Palace

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=217902

    Description

    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 magni cent 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 ght 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 re lasted
    for more than three months, renouncing the end of Qin dynasty.
    Several years later, Liu Bang defeated Xiangyu and became the rst 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 gures below shows 3 situations which are not quali ed (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 rst 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 quali ed 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

    HINT

    题意

    平面给你n个点,让你找到两个和坐标轴平行的矩形,然后要求这两个矩形要么内含,要么相离

    然后输出能够组成的最大面积

    题解:

    首先我们枚举矩形,只用n^2枚举就好了

    只用枚举对角线,然后枚举之后,我们就暴力去判断就好了

    判断两种情况,想清楚了,还是很简单的

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<iostream>
    #include<cstring>
    using namespace std;
    
    int mp[250][250];
    struct node
    {
        int x,y;
    };
    node p[34];
    int In(node a,node c,node b)
    {
        if(a.x<=b.x&&a.x>=c.x&&a.y<=b.y&&a.y>=c.y)
            return 1;
        return 0;
    }
    int No_In(node a,node c,node b)
    {
        if(a.x<b.x&&a.x>c.x&&a.y<b.y&&a.y>c.y)
            return 1;
        return 0;
    }
    int check(node a,node b,node c,node d)
    {
        node t1[4],t2[4];
        t1[0].x=min(a.x,b.x);t1[0].y=min(a.y,b.y);
        t1[1].x=max(a.x,b.x);t1[1].y=min(a.y,b.y);
        t1[2].x=min(a.x,b.x);t1[2].y=max(a.y,b.y);
        t1[3].x=max(a.x,b.x);t1[3].y=max(a.y,b.y);
    
        t2[0].x=min(c.x,d.x);t2[0].y=min(c.y,d.y);
        t2[1].x=max(c.x,d.x);t2[1].y=min(c.y,d.y);
        t2[2].x=min(c.x,d.x);t2[2].y=max(c.y,d.y);
        t2[3].x=max(c.x,d.x);t2[3].y=max(c.y,d.y);
    
        for(int i=0;i<4;i++)
        {
            //cout<<t1[i].x<<" "<<t1[i].y<<endl;
            if(mp[t1[i].x][t1[i].y]==0)
                return 0;
        }
    
        for(int i=0;i<4;i++)
        {
            //cout<<t2[i].x<<" "<<t2[i].y<<endl;
            if(mp[t2[i].x][t2[i].y]==0)
                return 0;
        }
    
        if(t1[0].x==t1[1].x)return 0;
        if(t1[0].y==t1[2].y)return 0;
        if(t2[0].x==t2[1].x)return 0;
        if(t2[0].y==t2[2].y)return 0;
    
        int flag = 0;
        for(int i=0;i<4;i++)
            if(No_In(t1[i],t2[0],t2[3]))
                flag++;
        if(flag==4)return (t2[3].x-t2[0].x)*(t2[3].y-t2[0].y);
    
        flag = 0;
        for(int i=0;i<4;i++)
            if(No_In(t2[i],t1[0],t1[3]))
                flag++;
        if(flag==4)return (t1[3].x-t1[0].x)*(t1[3].y-t1[0].y);
    
        for(int i=0;i<4;i++)
            if(In(t1[i],t2[0],t2[3]))
                return 0;
        for(int i=0;i<4;i++)
            if(In(t2[i],t1[0],t1[3]))
                return 0;
    
        return (t2[3].x-t2[0].x)*(t2[3].y-t2[0].y) + (t1[3].x-t1[0].x)*(t1[3].y-t1[0].y);
    }
    int main()
    {
        int n;
        while(scanf("%d",&n)!=EOF)
        {
            memset(mp,0,sizeof(mp));
            if(n==0)break;
            for(int i=1;i<=n;i++)
            {
                scanf("%d%d",&p[i].x,&p[i].y);
                mp[p[i].x][p[i].y]=1;
            }
            int ans = 0;
            for(int i=1;i<=n;i++)
            {
                for(int j=i+1;j<=n;j++)
                {
                    for(int t=1;t<=n;t++)
                    {
                        for(int k=t+1;k<=n;k++)
                        {
                            if(i==t&&j==k)continue;
                            int Area = check(p[i],p[j],p[t],p[k]);
                            if(Area!=0)
                            {
                                //printf("%d %d %d %d %d %d %d %d
    ",p[i].x,p[i].y,p[j].x,p[j].y,p[t].x,p[t].y,p[k].x,p[k].y);
                                //cout<<Area<<endl;
                            }
                            ans = max(ans,Area);
                        }
                    }
                }
            }
            if(ans==0)printf("imp
    ");
            else printf("%d
    ",ans);
        }
    }
  • 相关阅读:
    python学习笔记(4)装饰器
    python学习笔记(3)函数
    python学习笔记(2)集合
    python学习笔记(1)字典
    nginx.conf文件内容详解
    关于斐波拉契数列引出的迭代器生成器的一点讨论
    MAC电脑运行python并发编程遇到的问题
    docker 11 :私有仓库搭建
    docker 10 :docker单机网络模式
    【转】C#环形队列
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5004590.html
Copyright © 2020-2023  润新知