HDU 5128.The E-pang Palace-计算几何
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
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.
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.
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
imp
题目就是让你找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-计算几何的更多相关文章
- HDU 5572 An Easy Physics Problem (计算几何+对称点模板)
HDU 5572 An Easy Physics Problem (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5572 Descripti ...
- HDU 5128 The E-pang Palace(2014广州赛区现场赛B题 计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5128 解题报告:在一个平面上给出n个点的坐标,用这n个点作为矩形的四个顶点,作两个矩形,要求两个矩形不 ...
- hdu - 5128 The E-pang Palace(枚举+计算几何)
http://acm.hdu.edu.cn/showproblem.php?pid=5128 给出n个点,求n个点组成两个矩形的最大面积. 矩形必须平行x轴,并且不能相交,但是小矩形在大矩形内部是可以 ...
- hdu 5128 The E-pang Palace
http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意:给定N个点,选出其中8个点组成两个矩形,使得两个矩形的面积和最大. 思路:找出所有的矩形,然后枚举, ...
- hdu 5129 (枚举) The E-pang Palace
题目;http://acm.hdu.edu.cn/showproblem.php?pid=5128. 给你n个点,问能否组成两个不相交的与坐标轴平行的矩形,能就输出两矩形的面积和,不能就输出一个字符串 ...
- hdu 1115:Lifting the Stone(计算几何,求多边形重心。 过年好!)
Lifting the Stone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 6697 Closest Pair of Segments (计算几何 暴力)
2019 杭电多校 10 1007 题目链接:HDU 6697 比赛链接:2019 Multi-University Training Contest 10 Problem Description T ...
- HDU 1392 Surround the Trees(凸包*计算几何)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1392 这里介绍一种求凸包的算法:Graham.(相对于其它人的解释可能会有一些出入,但大体都属于这个算 ...
- HDU 3264 Open-air shopping malls (计算几何-圆相交面积)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3264 题意:给你n个圆,坐标和半径,然后要在这n个圆的圆心画一个大圆,大圆与这n个圆相交的面积必须大于等 ...
- HDU 3103 Shoring Up the Levees(计算几何 搜寻区域)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=3103 Problem Description The tiny country of Waterlog ...
随机推荐
- String.replaceAll()方法替换字符串中的反斜杠(\)
replaceAll()方法实际是采用正则表达式的规则去匹配的. 在regex中"\\"表示一个"\",在java中一个"\"也要用&quo ...
- 上下文管理器 contextlib
from contextlib import contextmanager @contextmanager def tag(name): print "<%s>" % ...
- jenkins修改job默认名字
${GIT_BRANCH,fullName="false"}-${BUILD_NUMBER}-${GIT_REVISION,length=12}-${deploy_rollback ...
- 「6月雅礼集训 2017 Day7」电报
[题目大意] 有n个岛屿,第i个岛屿有有向发射站到第$p_i$个岛屿,改变到任意其他岛屿需要花费$c_i$的代价,求使得所有岛屿直接或间接联通的最小代价. $1 \leq n \leq 10^5, 1 ...
- bzoj 4034: [HAOI2015]树上操作——树链剖分
Description 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个 操作,分为三种: 操作 1 :把某个节点 x 的点权增加 a . 操作 2 :把某个节点 x 为根的子树中 ...
- idea 导入 java json 包
1.java 项目导包 找到 External Libraries 下面的java版本包,在点击鼠标右键.直接找到jar路径全部选中导入即可.
- MSSQL DBOtherSQL
--------------------------查询表中的数据------------------------------ --1.请查询出MyStudent表中的所有数据 --下面的语句表示查询 ...
- bzoj 1188 SG函数
首先我们可以把一个石子看成一个单独的游戏,那么我们可以发现所有位置的石子至于奇偶有关,因为某一个人操作其中的一个石子,我们可以用相同的石子做相同的操作,所以我们只需要保留下所有位置的01,那么对于每个 ...
- kolakoski序列
搜狐笔试=.= 当时少想一个slow的指针..呜呜呜哇的一声哭出来 function kolakoski(token0, token1) { token0 = token ...
- 大原則 研讀 spec 與 code 的 心得
最近在研究 stm32f429i-disc0 的 device tree source code, 並且 參造 Devicetree Specification Release 0.1, 在 dts ...