The E-pang Palace

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

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
 

题目就是让你找8个点,组成与坐标系平行的矩形,输出最大面积。题目有个坑,,当其中一个在另一个里面的时候是满足的。

首先枚举,找左下角和右上角的点,看是否存在左上和右下的点,然后把符合条件的矩形先保存起来,然后判断是否有覆盖的部分,然后找最大值就可以。

代码:

 //5128-B-计算几何
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii; const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=1e4+;
const int maxm=+;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 struct node{
int x,y; bool operator<(const node &a) const{
if(x==a.x) return y<a.y;
else return x<a.x;
}
}a[maxn]; struct rectangle{
node p1,p2;
int area;
}rec[maxn]; map<node,int> mp; int judge(int i,int j)
{
if(rec[i].p2.x<rec[j].p1.x) return ;
if(rec[i].p2.y<rec[j].p1.y) return ;
if(rec[i].p1.x>rec[j].p2.x) return ;
if(rec[i].p1.y>rec[j].p2.y) return ;
if(rec[i].p1.x<rec[j].p1.x&&rec[i].p1.y<rec[j].p1.y&&rec[i].p2.x>rec[j].p2.x&&rec[i].p2.y>rec[j].p2.y) return ;
else return ;
} int main()
{
int n;
while(scanf("%d",&n)&&n){
mp.clear();
for(int i=;i<n;i++){
scanf("%d%d",&a[i].x,&a[i].y);
mp[a[i]]=;
}
sort(a,a+n);
int h=;
for(int i=;i<n;i++){
for(int j=i+;j<n;j++){
if(a[j].x>a[i].x&&a[j].y>a[i].y){
node t1,t2;
t1.x=a[i].x;t1.y=a[j].y;
t2.x=a[j].x;t2.y=a[i].y;
if(mp[t1]&&mp[t2]){
rec[h].p1.x=a[i].x;rec[h].p1.y=a[i].y;
rec[h].p2.x=a[j].x;rec[h].p2.y=a[j].y;
rec[h++].area=(a[j].y-a[i].y)*(a[j].x-a[i].x);
}
}
}
}
int ans=-;
for(int i=;i<h;i++){
for(int j=;j<h;j++){
if(judge(i,j)==){
ans=max(ans,rec[i].area+rec[j].area);
}
else if(judge(i,j)==){
ans=max(ans,rec[i].area);
}
}
}
if(ans==-)printf("imp\n");
else printf("%d\n",ans);
}
}

溜了。

HDU 5128.The E-pang Palace-计算几何的更多相关文章

  1. HDU 5572 An Easy Physics Problem (计算几何+对称点模板)

    HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...

  2. HDU 5128 The E-pang Palace(2014广州赛区现场赛B题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5128 解题报告:在一个平面上给出n个点的坐标,用这n个点作为矩形的四个顶点,作两个矩形,要求两个矩形不 ...

  3. hdu - 5128 The E-pang Palace(枚举+计算几何)

    http://acm.hdu.edu.cn/showproblem.php?pid=5128 给出n个点,求n个点组成两个矩形的最大面积. 矩形必须平行x轴,并且不能相交,但是小矩形在大矩形内部是可以 ...

  4. hdu 5128 The E-pang Palace

    http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意:给定N个点,选出其中8个点组成两个矩形,使得两个矩形的面积和最大. 思路:找出所有的矩形,然后枚举, ...

  5. hdu 5129 (枚举) The E-pang Palace

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5128. 给你n个点,问能否组成两个不相交的与坐标轴平行的矩形,能就输出两矩形的面积和,不能就输出一个字符串 ...

  6. hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)

    Lifting the Stone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. HDU 6697 Closest Pair of Segments (计算几何 暴力)

    2019 杭电多校 10 1007 题目链接:HDU 6697 比赛链接:2019 Multi-University Training Contest 10 Problem Description T ...

  8. HDU 1392 Surround the Trees(凸包*计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...

  9. HDU 3264 Open-air shopping malls (计算几何-圆相交面积)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...

  10. HDU 3103 Shoring Up the Levees(计算几何 搜寻区域)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3103 Problem Description The tiny country of Waterlog ...

随机推荐

  1. CentOS安装JDK环境

    一:查看当前系统的java环境 [elsearch@localhost data]$ rpm -qa | grep jdk 二:卸载原有的jdk [elsearch@localhost /]$ yum ...

  2. MyBatis框架的使用及源码分析(一) 配置与使用

    我们先来看一个例子,简单的了解一下mybatis的mapper接口方式的使用. package org.mybatis.spring.sample; import org.apache.ibatis. ...

  3. Php扩展--seasLog日志扩展安装

    安装/配置 编译安装 wge thttp://pecl.php.net/get/SeasLog-1.4.4.tgz tar -zxvfSeasLog-1.4.4.tgz cd SeasLog-1.4. ...

  4. hihocoder1445 后缀自动机二·重复旋律5

    传送门:http://hihocoder.com/problemset/problem/1445 [题解] 大概看了一天的后缀自动机,总算懂了一些 这篇文章写的非常好,诚意安利:Suffix Auto ...

  5. 【洛谷 P4934】 礼物 (位运算+DP)

    题目链接 位运算+\(DP\)=状压\(DP\)?(雾 \(a\&b>=min(a,b)\)在集合的意义上就是\(a\subseteq b\) 所以对每个数的子集向子集连一条边,然后答案 ...

  6. Angular2.0 基础: Form

    对于Angular2.0 的Form表单中的隐藏和验证,个人觉得还是挺有意思的. 1.通过ngModel 跟踪修改状态与验证. 在表单中使用 ngModel 可以获得更多的控制权,包括一些常用的验证. ...

  7. 如何修改或美化linux终端

    先丢一张效果图: 如何让您的 LD 的终端更具个性呢?首先,我们需要了解下面几点知识.A:配置文件 个人配置文件:~/.bashrc全局设定文件:/etc/bash.bashrc(修改需要管理员权限) ...

  8. 数据结构--Avl树的创建,插入的递归版本和非递归版本,删除等操作

    AVL树本质上还是一棵二叉搜索树,它的特点是: 1.本身首先是一棵二叉搜索树.   2.带有平衡条件:每个结点的左右子树的高度之差的绝对值最多为1(空树的高度为-1).   也就是说,AVL树,本质上 ...

  9. libSVM笔记之(一)在matlab环境下安装配置libSVM

    本文为原创作品,转载请注明出处 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和http://www.cnblogs.com/xujianqing 台湾林智仁教 ...

  10. linux下终端游戏

    sl 一列火车 oneko 一只淘气的小猫