现在的位置: 首页 > 综合 > 正文

hdu5128 The E-pang Palace

2019年11月06日 ⁄ 综合 ⁄ 共 4145字 ⁄ 字号 评论关闭

The E-pang Palace

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 1073    Accepted Submission(s): 766

Problem 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 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
 

Source
2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大)

枚举两个矩形然后判断是否可以算出面积不断更新ans

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
struct point
{
    int x,y;
    point(){}
    point(int x,int y)
    {
        this->x=x;
        this->y=y;
    }
};
bool vis[210][210];
bool cross(point one,point two,point three,point four)
{
    return min(one.x,two.x)<=max(three.x,four.x)&&
            min(one.y,two.y)<=max(three.y,four.y)&&
            min(three.x,four.x)<=max(one.x,two.x)&&
            min(three.y,four.y)<=max(one.y,two.y);
}
bool isin(point one,point two,point three,point four)
{
    return min(one.x,two.x)<three.x&&three.x<max(one.x,two.x)&&
            min(one.y,two.y)<three.y&&three.y<max(one.y,two.y)&&
            min(one.x,two.x)<four.x&&four.x<max(one.x,two.x)&&
            min(one.y,two.y)<four.y&&four.y<max(one.y,two.y);
}
int cnt(point one,point two,point three,point four)
{
    int s1=abs((one.x-two.x)*(one.y-two.y));
    int s2=abs((three.x-four.x)*(three.y-four.y));
    if(isin(one,two,three,four))
        return s1;
    if(isin(three,four,one,two))
        return s2;
    if(cross(one,two,three,four))
        return 0;
    return s1+s2;
}
bool isok(point one,point two)
{
    return one.x!=two.x&&one.y!=two.y&&
    vis[min(one.x,two.x)][min(one.y,two.y)]&&
    vis[min(one.x,two.x)][max(one.y,two.y)]&&
    vis[max(one.x,two.x)][min(one.y,two.y)]&&
    vis[max(one.x,two.x)][max(one.y,two.y)];
}
int main()
{
    int n;
    while(cin>>n&&n!=0)
    {
        vector<point>box;
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
        {
            int x,y;
            cin>>x>>y;
            box.push_back(point(x,y));
            vis[x][y]=1;
        }
        int ans=0;
        for(int i=0;i<n;i++)
        {
            point one,two,three,four;
            one=box[i];
            for(int j=i+1;j<n;j++)
            {
                two=box[j];
                if(isok(one,two))
                {
                    for(int ii=i+1;ii<n;ii++)
                    {
                        three=box[ii];
                        for(int jj=ii+1;jj<n;jj++)
                        {
                            four=box[jj];
                            if(isok(three,four))
                                ans=max(ans,cnt(one,two,three,four));
                        }
                    }
                }
            }
        }
        if(ans==0)
            cout<<"imp"<<endl;
        else
            cout<<ans<<endl;
    }
}

抱歉!评论已关闭.