HDU5128 The E-pang Palace(计算几何,枚举)
来源:互联网 发布:忻州网络第一传媒 编辑:程序博客网 时间:2024/05/18 01:04
题目:
The E-pang Palace
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)Total Submission(s): 3468 Accepted Submission(s): 2049
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.
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.
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
80 01 00 11 10 21 20 31 380 02 00 22 21 23 21 33 30
Sample Output
2imp
Source
2014ACM/ICPC亚洲区广州站-重现赛(感谢华工和北大)
Recommend
liuyiding | We have carefully selected several similar problems for you: 6022 6021 6020 6019 6018
给了n个点,然后你在其中找出两个最大的矩形,算出面积,但是选出的矩形要满足一些条件,不能接触和重叠
在这里我们枚举它的对角线,通过这种方式来枚举矩形。
套用一下题解:
由于n只有4到30这么大,所以直接暴力求解就可以了。
一、首先我们要判断存不存在矩形,如何判断?
这里有个小技巧,通过确定两个点的对角线来判断能不能构成矩形。
如图:
我们先判断A,B这两点所连的直线是不是水平或者竖直,如果是就跳过。如果是则判断C,D这两个点是不是都存在。如果存在则能构成矩形,如果不能,就不能构成。
然后我们在确定第二个矩形。
二、第二个矩形的确定。
第二个矩形(假设是EFGH)的确定首先要排除点A,B,C,D这四个点,并且EFGH这四个点不能有任何一个在ABCD内(包括边与定点)。(如题图)
但是这里有一种特殊情况。如图:
我们确定了ABCD,但是EFGH包含了ABCD,所以我们要反过来判断ABCD是不是在EFGH内。如果在就取EFGH的面积,如果不在就取ABCD+AEFHG的面积
代码:
#include <cstdio>#include <cstring>#include <cctype>#include <string>#include <set>#include <iostream>#include <stack>#include <cmath>#include <queue>#include <vector>#include <algorithm>#define mem(a,b) memset(a,b,sizeof(a))#define inf 0x3f3f3f3f#define mod 10000007#define debug() puts("what the fuck!!!")#define N 50#define ll long longusing namespace std;struct point//坐标点{ int x,y;} g[N];struct ju//矩形{ point a,b;//矩形a一定在矩形b的右下方 int area;} zz[N*N];int map[300][300];bool cmp(point a,point b){ if(a.x==b.x) return a.y<b.y; return a.x<b.x;}int judge(int i,int j){ //确定是都相离 if(zz[i].a.x>zz[j].b.x) return 1; if(zz[i].a.y>zz[j].b.y) return 1; if(zz[j].a.x>zz[i].b.x) return 1; if(zz[j].a.y>zz[i].b.y) return 1; //是否有i包含j if(zz[i].a.x<zz[j].a.x&&zz[i].a.y<zz[j].a.y&&zz[i].b.x>zz[j].b.x&&zz[i].b.y>zz[j].b.y) return 2; else return 0;}int main(){ int n; while(scanf("%d",&n)&&n) { mem(map,0); for(int i=0; i<n; i++) { scanf("%d%d",&g[i].x,&g[i].y); map[g[i].x][g[i].y]=1; } sort(g,g+n,cmp); int len=0; for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) { if(g[j].x>g[i].x&&g[j].y>g[i].y)//判断两个点能不能构成矩形 { if(map[g[i].x][g[j].y]&&map[g[j].x][g[i].y])//判断这两个点的组合是否存在 { zz[len].a.x=g[i].x; zz[len].a.y=g[i].y; zz[len].b.x=g[j].x; zz[len].b.y=g[j].y; zz[len++].area=(g[j].x-g[i].x)*(g[j].y-g[i].y); } } } int maxx=0; for(int i=0; i<len; i++) for(int j=i+1; j<len; j++) { if(judge(i,j)==1) maxx=max(maxx,zz[i].area+zz[j].area); else if(judge(i,j)==2) maxx=max(maxx,zz[i].area); } if(maxx) printf("%d\n",maxx); else puts("imp"); } return 0;}
0 0
- HDU5128 The E-pang Palace(计算几何,枚举)
- hdu5128 The E-pang Palace
- HDOJ 5128 The E-pang Palace 暴力枚举+计算几何
- HDU 5128 The E-pang Palace(枚举,几何)
- hdu 5128 The E-pang Palace(计算几何:暴力枚举)
- hdu 5128 The E-pang Palace (计算几何+暴力枚举)
- hdu 5128 The E-pang Palace(计算几何,暴力枚举)
- 2014广州亚洲现场赛/hdu 5128 The E-pang Palace(计算几何:暴力枚举)
- HDU5128 The E-pang Palace(2014年广州赛区)
- The E-pang Palace
- Hdu5128 - The E-pang Palac
- hdu 5128 The E-pang Palace(几何暴力)
- HDU 5128 The E-pang Palace
- HDU 5128 The E-pang Palace
- HDU.5128 The E-pang Palace
- HDU 5218 The E-pang Palace (简单几何—2014广州现场赛)
- HDU 5128 The E-pang Palace 几何题 求两个不相交矩阵面积和
- HDU 5128 The E-pang Palace (暴力+几何思维 详解)
- CF679A:Bear and Prime 100(交互 & 数论)
- 事件+存储过程+触发器
- 完美解决RadioGroup setOnCheckedChangedListener 多次调用问题
- Ext.menu.Menu菜单栏
- angular的ui-router小demo
- HDU5128 The E-pang Palace(计算几何,枚举)
- AngularJS-路由
- 运行tomcat出现set?JAVA_OPTS 不是内部或外部命令
- priority_queue 结构体类型
- 关于获取时间戳
- QAN API error: "qh.Profile: No query classes for selected instance and time range. Please check whet
- 通过浏览器geolocation属性获取经度和纬度(1)
- oracle hr样例数据库经典查询语句
- JavaScript学习笔记19-for循环