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

题目大意:给你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

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

#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
*/
时间: 2024-08-04 02:46:59

HDU 5128 The E-pang Palace(暴力瞎搞)的相关文章

CodeForces 398A Cards 贪心 暴力 瞎搞

搞了一晚上了快,各种YY乱搞啊,终于过了,一开始YY的都是错的,觉得 这道题目a,b的范围都是10^5,那就暴力枚举b被分成了几份,然后再继续YY,只用一个o去分隔x,这样最后剩下的o再集中在一起,也就是x的份数总是比o的份数多一份,也就是尽可能把x分开,尽可能把o集中在一块,前面都把x分开了,一个o分开两份x,后面还能有一大堆的o在一起,这样就满足了,然后又出错了,因为分成几份,有余数的,比如b = 6,你要分成4份,我以开始是分成 1  1  1  3这样子,这样不行,应该分成 1 1 2

HDU 5926 Basic Mr. Frog’s Game 瞎搞

Mr. Frog’s Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1273    Accepted Submission(s): 625 Problem Description One day, Mr. Frog is playing Link Game (Lian Lian Kan in Chinese). In this

HDU 1022 Train Problem I 用栈瞎搞

题目大意:有n辆火车,按一定的顺序进站(第一个字符串顺序),问是否能按规定的顺序出站(按第二个字符串的顺序出去),如果能输出每辆火车进出站的过程. 题目思路:栈的特点是先进后出,和题意类似,还有有一种情况是:开进来立马有开出去.并用vis[]数组的0,1标记进出站情况. 具体看代码 #include<cstdio> #include<cstring> #include<cmath> #include<queue> #include<algorithm&

HDU 5024 Wang Xifeng&#39;s Little Plot(暴力枚举+瞎搞)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5024 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>) is one of the Four Great Classical Novels of Chinese literature, and it is commonly regarded as the best one. Thi

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

HDU 4937 (杭电多校 #7 1003题)Lucky Number(瞎搞)

题目地址:HDU 4937 多校的题以后得重视起来...每道题都错好多次...很考察细节.比如这道....WA了无数次.... 这题的思路自己真心想不到...这题是将进制后的数分别是1位,2位,3位和更多位的分开来计算. 当是1位的时候,显然只有3到6,此时只能是-1 当是2位的时候,可以转换成一元一次方程求解 当是3位的时候,可以转换成一元二次方程求解 当是4位的时候,此时最多也只有7000个数,7000^3接近1e12.所以剩下的直接枚举进制数来判断即可. 代码如下: #include <i

HDU 4923 Room and Moor(瞎搞题)

瞎搞题啊.找出1 1 0 0这种序列,然后存起来,这种情况下最好的选择是1的个数除以这段的总和.然后从前向后扫一遍,变扫边进行合并.每次合并,合并的是他的前驱.这样到最后从t-1找出的那条链就是最后满足条件的数的大小. Room and Moor Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 307    Accepted Su

HDU 4925 Apple Tree (瞎搞)

找到规律,各一个种一棵树,或者施肥.先施肥,先种树一样. Apple Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 197    Accepted Submission(s): 135 Problem Description I've bought an orchard and decide to plant some

hdu 4883 TIANKENG’s restaurant(暴力)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4883 Problem Description TIANKENG manages a restaurant after graduating from ZCMU, and tens of thousands of customers come to have meal because of its delicious dishes. Today n groups of customers come t