HDU 5128 The E-pang Palace (排序+暴力)2014 ICPC 广州站现场赛

The E-pang Palace

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


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
 

题意:给你N个点,求这N个点组成的矩形中,排除相交,重边,重点等几种情况后的两个面积和最大的矩形的面积。

分析:看到N的范围比较小,考虑暴力搞搞,没想到就过了,时间还很短。注意要考虑的两个矩形相互包含的那种情况,取外面矩形的面积作为最终面积。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cctype>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <fstream>
#define debug "output for debug\n"
#define pi (acos(-1.0))
#define eps (1e-8)
#define inf 0x3f3f3f3f
#define ll long long int
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
using namespace std;
const int mod = 1000000007;
const int Max = 1000005;
int n,cnt;
struct node
{
    int x,y;
}p[Max];
struct mar
{
    node a,b,c,d;
}num[Max];
bool cmp(node u,node v)
{
    if(u.x==v.x)
        return u.y>v.y;
    return u.x<v.x;
}
bool judge(int i,int j,int k,int l)
{
    if(p[i].x!=p[j].x) return false;
    if(p[i].y!=p[k].y) return false;
    if(p[j].y!=p[l].y) return false;
    if(p[k].x!=p[l].x) return false;
    return true;
}
void gao()
{
    cnt=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                for(int l=k+1;l<n;l++)
                {
                    if(judge(i,j,k,l)) num[cnt].a=p[i],num[cnt].b=p[j],num[cnt].c=p[k],num[cnt++].d=p[l];//(排序的原因,矩形不重复,而且满足左上,左下,右上右下的顺序)
                }
            }
        }

    }
}
bool flag;
int cal(mar tmp)
{
    int ch=abs(tmp.a.y-tmp.b.y);
    int ku=abs(tmp.a.x-tmp.c.x);
    return ch*ku;
}
bool check(mar u,mar v)
{
    if(u.a.x<v.a.x&&u.a.y>v.a.y&&u.b.x<v.b.x&&u.b.y<v.b.y&&u.c.x>v.c.x&&u.c.y>v.c.y&&u.d.x>v.d.x&&u.d.y<v.d.y){flag=true;return true;}//特判包含的情况
    int maxx,minx;
    int maxy,miny;
    int chang,kuan;
    chang=abs(u.c.x-u.a.x)+abs(v.c.x-v.a.x);
    kuan=abs(u.a.y-u.b.y)+abs(v.a.y-v.b.y);
    maxx=max(u.c.x,v.c.x);
    minx=min(u.a.x,u.a.x);
    maxy=max(u.a.y,v.a.y);
    miny=min(u.b.y,v.b.y);
    //printf("%d,%d  ,  %d,%d\n",maxx,minx,maxy,miny);
    int tx=maxx-minx;
    int ty=maxy-miny;
    //printf("kkkkk %d,%d  ,  %d,%d\n",chang,kuan,tx,ty);
    if(tx<=chang&&ty<=kuan)
    {
        //cout<<"lalalallalala"<<endl;
        return false;
    }
    return true;
}
void print(mar u)
{
    printf("(%d,%d)    (%d,%d)\n",u.a.x,u.a.y,u.c.x,u.c.y);
    printf("(%d,%d)    (%d,%d)\n",u.b.x,u.b.y,u.d.x,u.d.y);
    puts("");
}
int main()
{
    while(scanf("%d",&n)&&n)
    {
        cnt=0;
        for(int i=0;i<n;i++)
            scanf("%d%d",&p[i].x,&p[i].y);
        if(n<8)
        {
            puts("imp");
            continue;
        }
        sort(p,p+n,cmp);//排完序之后处理起来更加方便
        gao();
        //cout<<cnt<<endl;
        //for(int i=0;i<cnt;i++)
            //print(num[i]);
        int ans=-1;
        for(int i=0;i<cnt-1;i++)
        {
            for(int j=i+1;j<cnt;j++)
            {
                flag=false;
                if(check(num[i],num[j]))
                {
                    //puts("shabi");
                    if(!flag)ans=max(ans,cal(num[i])+cal(num[j]));
                    else ans=max(ans,max(cal(num[i]),cal(num[j])));
                }
            }
        }
        if(ans==-1)
            puts("imp");
        else
            printf("%d\n",ans);
    }
    return 0;
}
/**
8
0 0
1 1
3 3
4 4
0 4
4 0
1 3
3 1


**/

题目链接: 点击打开链接





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值