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个点,组成与坐标系平行的矩形,输出最大面积。题目有个坑,,当其中一个在另一个里面的时候是满足的。

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

代码:

  1. //5128-B-计算几何
  2. #include<iostream>
  3. #include<cstdio>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<bitset>
  7. #include<cassert>
  8. #include<cctype>
  9. #include<cmath>
  10. #include<cstdlib>
  11. #include<ctime>
  12. #include<deque>
  13. #include<iomanip>
  14. #include<list>
  15. #include<map>
  16. #include<queue>
  17. #include<set>
  18. #include<stack>
  19. #include<vector>
  20. using namespace std;
  21. typedef long long ll;
  22. typedef pair<int,int> pii;
  23.  
  24. const double PI=acos(-1.0);
  25. const double eps=1e-;
  26. const ll mod=1e9+;
  27. const int inf=0x3f3f3f3f;
  28. const int maxn=1e4+;
  29. const int maxm=+;
  30. #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  31. #define lson l,m,rt<<1
  32. #define rson m+1,r,rt<<1|1
  33.  
  34. struct node{
  35. int x,y;
  36.  
  37. bool operator<(const node &a) const{
  38. if(x==a.x) return y<a.y;
  39. else return x<a.x;
  40. }
  41. }a[maxn];
  42.  
  43. struct rectangle{
  44. node p1,p2;
  45. int area;
  46. }rec[maxn];
  47.  
  48. map<node,int> mp;
  49.  
  50. int judge(int i,int j)
  51. {
  52. if(rec[i].p2.x<rec[j].p1.x) return ;
  53. if(rec[i].p2.y<rec[j].p1.y) return ;
  54. if(rec[i].p1.x>rec[j].p2.x) return ;
  55. if(rec[i].p1.y>rec[j].p2.y) return ;
  56. 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 ;
  57. else return ;
  58. }
  59.  
  60. int main()
  61. {
  62. int n;
  63. while(scanf("%d",&n)&&n){
  64. mp.clear();
  65. for(int i=;i<n;i++){
  66. scanf("%d%d",&a[i].x,&a[i].y);
  67. mp[a[i]]=;
  68. }
  69. sort(a,a+n);
  70. int h=;
  71. for(int i=;i<n;i++){
  72. for(int j=i+;j<n;j++){
  73. if(a[j].x>a[i].x&&a[j].y>a[i].y){
  74. node t1,t2;
  75. t1.x=a[i].x;t1.y=a[j].y;
  76. t2.x=a[j].x;t2.y=a[i].y;
  77. if(mp[t1]&&mp[t2]){
  78. rec[h].p1.x=a[i].x;rec[h].p1.y=a[i].y;
  79. rec[h].p2.x=a[j].x;rec[h].p2.y=a[j].y;
  80. rec[h++].area=(a[j].y-a[i].y)*(a[j].x-a[i].x);
  81. }
  82. }
  83. }
  84. }
  85. int ans=-;
  86. for(int i=;i<h;i++){
  87. for(int j=;j<h;j++){
  88. if(judge(i,j)==){
  89. ans=max(ans,rec[i].area+rec[j].area);
  90. }
  91. else if(judge(i,j)==){
  92. ans=max(ans,rec[i].area);
  93. }
  94. }
  95. }
  96. if(ans==-)printf("imp\n");
  97. else printf("%d\n",ans);
  98. }
  99. }

溜了。

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. linux tar指定文件到指定目录

    项目需求:从远处拷贝压缩文件到本地后并解压,解压后的部分文件拷贝并重命名到其他目录 需求拆分:1.拷贝文件 2.解压文件 3.批量重命名 步骤一查看:http://www.cnblogs.com/dd ...

  2. Java设计模式の单例模式

    -------------------------------------------------- 目录 1.定义 2.常见的集中单例实现 a.饿汉式,线程安全 但效率比较低 b.单例模式的实现:饱 ...

  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. mysql 服务端事务和客户端事务对比分析

    之前做mysql事务测试的时候都是在mysql服务端存储过程里面包含事务. 例如: CREATE DEFINER=`root`@`localhost` PROCEDURE `Test`(out deb ...

  5. Linux while 和 read 的用法

    Reference: [ linux man doc ] [ CSDN roler_ ] [ Reads from the file descriptor] read 命令说明 SYNTAX : re ...

  6. Network(POJ3694+边双连通分量+LCA)

    题目链接:http://poj.org/problem?id=3694 题目: 题意:给你一个n个点m条边的无向连通图,进行q次操作,每次操作在u和v之间加一条边,问每次操作之后“桥”的数量. 思路: ...

  7. httpd -v command not found

    使用 find / -name "apachectl"查找文件目录下执行 ./apachectl -v

  8. 移动端页面使用rem布局

    阿里团队的高清布局方案代码 所谓高清方案就是根据设备屏幕的DPR(设备像素比,又称DPPX,比如dpr=2时,表示1个CSS像素由4个物理像素点组成) 动态设置 html 的font-size, 同时 ...

  9. Bitmap算法应用实例(转)

    关于数据库查询工作,例如有如下数据库表 要想统计所有90后的程序员该怎么做呢?用一条求交集的SQL语句即可: Select count(distinct Name) as 用户数 from table ...

  10. Spring注解@Resource和@Autowired区别对比、spring扫描的默认bean的Id、程序获取spring容器对象

    -------------------------注解扫面的bean的ID问题-------------------------- 0.前提需要明白注解扫描出来的bean的id默认是类名首字母小写,当 ...