HDU 5128 The E-pang Palace(暴力)

The E-pang Palace

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)

Total Submission(s): 251    Accepted Submission(s): 93

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 <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

const int MAXN = 35;
const int MAXM = 210;

struct Node {
    int x, y;
} node[MAXN];

int n, G[MAXM][MAXM], ans;

void init() {
    memset(G, -1, sizeof(G));
    ans = -1;
}

void input() {
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &node[i].x, &node[i].y);
        G[node[i].x][node[i].y] = i;
    }
}

int judge(int a, int b, int c, int d, int e, int f, int g, int h) {
    int minX = node[a].x, maxX = node[c].x, minY = node[a].y, maxY = node[c].y;
    int minX2 = node[e].x, maxX2 = node[g].x, minY2 = node[e].y, maxY2 = node[g].y;
    if (minX2 >= minX && minX2 <= maxX && minY2 >= minY && minY2 <= maxY) {
        if (maxX2 > minX && maxX2 < maxX && maxY2 > minY && maxY2 < maxY) {
            return (maxX - minX) * (maxY - minY);
        } else {
            return -1;
        }
    } else {
        return (maxX - minX) * (maxY - minY) + (maxX2 - minX2) * (maxY2 - minY2);
    }
    return -1;
}

void solve() {
    for (int a = 0; a < n; a++) {
        for (int c = a+1; c < n; c++) {
            int minX = node[a].x, maxX = node[c].x, minY = node[a].y, maxY = node[c].y;
            if (minX > maxX || minY > maxY) continue;
            int b = G[minX][maxY], d = G[maxX][minY];
            if (b != -1 && d != -1 && b != d) {
                if (a != b && a != d && b != c && d != c) {
                    for (int e = a+1; e < n; e++) {
                        if (e == a || e == b || e == c || e == d) continue;
                        for (int g = e+1; g < n; g++) {
                            if (g == a || g == b || g == c || g == d) continue;
                            int minX2 = node[e].x, maxX2 = node[g].x, minY2 = node[e].y, maxY2 = node[g].y;
                            if (minX2 > maxX2 || minY2 > maxY2) continue;
                            int f = G[minX2][maxY2], h = G[maxX2][minY2];
                            if (f != -1 && h != -1 && f != h) {
                                if (e != f && e != h && f != g && h != g) {
                                    ans = max(ans, judge(a, b, c, d, e, f, g, h));
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    if (ans == -1) {
        printf("imp\n");
    } else {
        printf("%d\n", ans);
    }
}

int main() {
    while (~scanf("%d", &n) && n) {
        init();
        input();
        solve();
    }
    return 0;
}
时间: 2024-10-28 16:53:49

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

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

hdu 4968 Improving the GPA (水 暴力枚举)

题目链接 题意:给平均成绩和科目数,求可能的最大学分和最小学分. 分析: 枚举一下,可以达到复杂度可以达到10^4,我下面的代码是10^5,可以把最后一个循环撤掉. 刚开始以为枚举档次的话是5^10,但是这个又不要求顺序,所以只是枚举个数就行了.. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <cmath&g

HDU 5616 Jam&#39;s balance(暴力枚举子集)

题目链接:点击打开链接 题意:有一个没有游标的天平,和n个秤砣,m个询问, 每次一个k,问可否秤出k这个重量. 秤砣可以放两边. 思路:因为n最大20, 暴力枚举子集. 因为可以放两边, 所以每次再跑一遍, 减去每个的重量, 将答案保存. 比赛的时候忘了限制边界,虽然过了终测数据, 却被人用大数据hack了(RE), 还是自己程序写的不够鲁棒, 思考的不完善. 细节参见代码: #include<cstdio> #include<cstring> #include<algori

hdu 4968 Improving the GPA(暴力枚举)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 Problem Description Xueba: Using the 4-Point Scale, my GPA is 4.0. In fact, the AVERAGE SCORE of Xueba is calculated by the following formula: AVERAGE SCORE = ∑(Wi * SCOREi) / ∑(Wi) 1<=i<=N where S

HDU 4876 ZCC loves cards(暴力剪枝)

HDU 4876 ZCC loves cards 题目链接 题意:给定一些卡片,每个卡片上有数字,现在选k个卡片,绕成一个环,每次可以再这个环上连续选1 - k张卡片,得到他们的异或和的数,给定一个L,问能组成[L,R]所有数字的情况下,R的最大值是多少 思路:暴力C(20, 6),然后对于每个序列去全排后模拟计算值, 不过之前要有个剪枝,全排前,先把k个数随机取数(即不用连续),然后如果这样还满足不了,那么连续的情况肯定也满足不了,直接结束,不进入全排.这样一来由于满足不了的情况实际上是占绝大

HDU 3131 One…Two…Five! (暴力搜索)

题目链接:HDU 3131 One-Two-Five! (暴力搜索) 题意:给出一串数字,要求用加,减,乘,除(5/2=2)连接(计算无优先级:5+3*6=8*6=48),求所有结果中,含有'3'且该数字出现频率最大,若频率相等,输出数字最大的. 暴力解决之 AC代码: #include <stdio.h> #include <map> #include <string.h> #include <algorithm> #define LL __int64 u

HDU 4858 项目管理(邻接表 暴力模拟)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4858 我们建造了一个大项目!这个项目有n个节点,用很多边连接起来,并且这个项目是连通的! 两个节点间可能有多条边,不过一条边的两端必然是不同的节点.每个节点都有一个能量值. 现在我们要编写一个项目管理软件,这个软件呢有两个操作:1.给某个项目的能量值加上一个特定值.2.询问跟一个项目相邻的项目的能量值之和.(如果有多条边就算多次,比如a和b有2条边,那么询问a的时候b的权值算2次). 解题报告:这个

HDU 1557 权利指数 状态压缩 暴力

HDU 1557 权利指数 状态压缩 暴力 ACM 题目地址:HDU 1557 权利指数 题意: 中文题,不解释. 分析: 枚举所有集合,计算集合中的和,判断集合里面的团体是否为关键团队. 代码: /* * Author: illuz <iilluzen[at]gmail.com> * File: 1557.cpp * Create Date: 2014-06-28 14:47:58 * Descripton: brute force/ set */ #include <cstdio&g

hdu 4932 Miaomiao&#39;s Geometry(暴力枚举)

Miaomiao's Geometry                                                                              Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description There are N point on X-axis . Miaomiao would like