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

HDU 5128 The E-pang Palace(暴力)

时间:2015-01-16 16:48:57      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:acm-icpc   acm2014   广州   

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
 


题目大意:

找出两个不相交的矩形的总面积,可以是回字型。


解题思路:

暴力即可。


参考代码:

#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;
}


HDU 5128 The E-pang Palace(暴力)

标签:acm-icpc   acm2014   广州   

原文地址:http://blog.csdn.net/wujysh/article/details/42777823

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