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. 再续前缘-apache.commons.beanutils的补充

    title: 再续前缘-apache.commons.beanutils的补充 toc: true date: 2016-05-32 02:29:32 categories: 实在技巧 tags: 插 ...

  2. Eclipse 调试

    F6:(Step Over)单步执行每一行程序: F8:(Resume)继续执行该程序直到下一个断点或程序结束: F5: (Step Into)跳入一个方法内部: F7:(Step Return)从当 ...

  3. 51nod 1873 高精度计算

    JAVA BigDecimal import java.util.*; import java.math.*; public class Main { public static void main( ...

  4. CSS浮动为什么不会遮盖同级元素

    1.问题描述 在W3CSchool学习web前端时,看完CSS定位-浮动这一节后,感觉没有什么问题.但是在CSS高级-分类这一节的中进行实践时,遇到了如下问题.测试地址:浮动的简单应用. 完整的htm ...

  5. 解决不走onActivityResult方法

    最近在开发公司项目,在使用startActivityForResult关联俩个Activity中,发现A跳转到B,B设置setResult之后,A没有执行onActivityResult,查找一下,发 ...

  6. xctf一道反序列化题

    题目地址:http://120.24.86.145:8006/test1/ 右键get源码: <?php $user = $_GET["txt"]; $file = $_GE ...

  7. Shell脚本 - nginx启动脚本

    OS:CentOS/Redhat 系列 并在 Centos 6.7 和 Centos 7.2 上测试正常 #!/bin/bash # # auth: daxin # time: 2018/07/10 ...

  8. MySQL 8.0 正式版 8.0.11 发布:比 MySQL 5.7 快 2 倍

    ySQL 8.0 正式版 8.0.11 已发布,官方表示 MySQL 8 要比 MySQL 5.7 快 2 倍,还带来了大量的改进和更快的性能! 注意:从 MySQL 5.7 升级到 MySQL 8. ...

  9. 一种面向云服务的UCON多义务访问控制方法及系统

    )设置每一云服务的义务项:建立每一云服务所包含的义务图:2)根据用户所请求的云服务查找该云服务的所有强制义务图和可选义务图,并提取该用户对该云服务的历史完成情况:3)对每一强制义务图,监控其每一义务项 ...

  10. gpio子系统和pinctrl子系统(中)

    pinctrl子系统核心实现分析 pinctrl子系统的内容在drivers/pinctrl文件夹下,主要文件有(建议先看看pinctrl内核文档Documentation/pinctrl.txt): ...