码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5128 The E-pang Palace(暴力瞎搞)

时间:2015-01-20 15:46:36      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

题目大意:给你n个点,让你组成矩形,然后如果有两个矩形不相交的话就计算他们的面积,求最大的两个矩形的面积并。注意的是回字型的嵌套,面积的并是最大的矩形的面积。

解题思路:暴力,枚举出来矩形,然后再暴力枚举两个矩形判断是否相交,是否为回字型。

The E-pang Palace

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


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
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <ctime>
#include <map>
#include <set>
#define eps 1e-9
///#define M 1000100
///#define LL __int64
#define LL long long
///#define INF 0x7ffffff
#define INF 0x3f3f3f3f
#define PI 3.1415926535898
#define zero(x) ((fabs(x)<eps)?0:x)
#define mod 1000000007
#define Read() freopen("autocomplete.in","r",stdin)
#define Write() freopen("autocomplete.out","w",stdout)
#define Cin() ios::sync_with_stdio(false)

using namespace std;



inline int read()
{
    char ch;
    bool flag = false;
    int a = 0;
    while(!((((ch = getchar()) >= '0') && (ch <= '9')) || (ch == '-')));
    if(ch != '-')
    {
        a *= 10;
        a += ch - '0';
    }
    else
    {
        flag = true;
    }
    while(((ch = getchar()) >= '0') && (ch <= '9'))
    {
        a *= 10;
        a += ch - '0';
    }
    if(flag)
    {
        a = -a;
    }
    return a;
}
void write(int a)
{
    if(a < 0)
    {
        putchar('-');
        a = -a;
    }
    if(a >= 10)
    {
        write(a / 10);
    }
    putchar(a % 10 + '0');
}

const int maxn = 201;

int mp[maxn][maxn];


struct node
{
    int x, y;
} f[maxn];

int vis[maxn];

struct node1
{
    int num[4];
}p[maxn];


int main()
{
    int n;
    while(~scanf("%d",&n) && n)
    {
        memset(mp, 0, sizeof(mp));
        for(int i = 1; i <= n; i++)
        {
            scanf("%d %d",&f[i].x, &f[i].y);
            mp[f[i].x][f[i].y] = i;
        }
        int ans = 0;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(i == j) continue;
                if(f[i].x <= f[j].x || f[i].y <= f[j].y) continue;
                int x1 = f[j].x;
                int y1 = f[i].y;
                int xp1 = mp[x1][y1];
                if(!xp1) continue;

                int x2 = f[i].x;
                int y2 = f[j].y;
                int xp2 = mp[x2][y2];
                if(!xp2) continue;

                p[ans].num[0] = i;
                p[ans].num[1] = j;
                p[ans].num[2] = xp1;
                p[ans++].num[3] = xp2;
            }
        }
        int Max = 0;

        for(int i = 0; i < ans; i++)
        {
            for(int j = 0; j < ans; j++)
            {
                if(i == j) continue;
                int flag = 0;
                for(int sk = 0; sk < 4; sk++)
                {
                    for(int sp = 0; sp < 4; sp++)
                    {
                        if(p[i].num[sk] == p[j].num[sp])
                        {
                            flag = 1;
                            break;
                        }
                    }
                }
                if(flag) continue;
                int a1 = p[i].num[0];
                int b1 = p[i].num[1];

                int a2 = p[j].num[0];
                int b2 = p[j].num[1];

                if(f[b1].x < f[b2].x && f[b1].y < f[b2].y && f[a2].x < f[a1].x && f[a2].y < f[a1].y)
                {
                    Max = max(Max, (f[a1].x-f[b1].x)*(f[a1].y-f[b1].y));
                    continue;
                }
                if(f[b2].x < f[b1].x && f[b2].y < f[b1].y && f[a1].x < f[a2].x && f[a1].y < f[a2].y)
                {
                    Max = max(Max, (f[a2].x-f[b2].x)*(f[a2].y-f[b2].y));
                    continue;
                }

                if(f[b1].x <= f[b2].x && f[b2].x <= f[a1].x && f[b1].y <= f[b2].y && f[b2].y <= f[a1].y
                   && (f[a2].x >= f[a1].x || f[a2].y >= f[a1].y))
                  {

                      continue;
                  }
               if(f[b1].x <= f[a2].x && f[a2].x <= f[a1].x && f[b1].y <= f[a2].y && f[a2].y <= f[a1].y
                  && (f[b2].x <= f[b1].x || f[b2].y <= f[b1].y))
                   {
                       continue;
                   }
                int c1 = p[i].num[2];
                int d1 = p[i].num[3];

                int c2 = p[j].num[2];
                int d2 = p[j].num[3];


                if(f[c1].x <= f[c2].x && f[c2].x <= f[d1].x && f[d1].y <= f[c2].y && f[c2].y <= f[c1].y
                  && (f[d2].x >= f[d1].x || f[d2].y <= f[d1].y))
                  {
                      continue;
                  }

                if(f[c1].x<=f[d2].x && f[d2].x <= f[d1].x && f[d1].y <= f[d2].y && f[d2].y <= f[c1].y
                  && (f[c2].x <= f[c1].x || f[c2].y >= f[c1].y))
                  {
                      continue;
                  }
                int sx = (f[a1].x-f[b1].x)*(f[a1].y-f[b1].y);
                int sy = (f[a2].x-f[b2].x)*(f[a2].y-f[b2].y);


                if(f[a1].x == f[a2].x && (f[a1].y <= f[a2].y && f[d1].y >= f[d2].y))
                {
                    continue;
                }
                if(f[b1].x == f[b2].x && (f[c1].y <= f[c2].y && f[b1].y >= f[b2].y))
                {
                    continue;
                }
                if(f[a1].y == f[a2].y && (f[c2].x <= f[c1].x && f[a1].x <= f[a2].x))
                {
                    continue;
                }

                if(f[b1].y == f[b2].y && f[b2].x <= f[b1].x && f[d1].x <= f[d2].x)
                {
                    continue;
                }

                Max = max(sx+sy, Max);
            }
        }

        if(!Max) cout<<"imp"<<endl;
        else cout<<Max<<endl;
    }
}

/*

8
0 0
0 3
3 3
3 0
1 1
1 2
2 2
2 1
*/



HDU 5128 The E-pang Palace(暴力瞎搞)

标签:

原文地址:http://blog.csdn.net/xu12110501127/article/details/42917945

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!