hdu - 5128 The E-pang Palace(枚举+计算几何)
http://acm.hdu.edu.cn/showproblem.php?pid=5128
给出n个点,求n个点组成两个矩形的最大面积.
矩形必须平行x轴,并且不能相交,但是小矩形在大矩形内部是可以的,面积就为大矩形的面积.
我是枚举一条对角线,然后去找另外两个点是否在坐标中存在这样就可以确定一个矩形,
同理可以枚举出另外有一个矩形,但是要注意坐标不能重复,
判断矩形相交的话,只要判断一个矩形的4个点是否有在另一个矩形的范围内即可.
#include<cstdio>
#include<cstring>
#include<set>
#include<iostream>
#include<algorithm>
using namespace std;
struct point
{
int x,y;
bool operator < (const point a) const
{
return x==a.x?y<a.y:x<a.x;
}
}p[],q1,q2,q3,q4; int check(point a,point b,point c) //注意区分是在矩形内部还是在矩形边上
{
if(a.x>=b.x&&a.x<=c.x&&a.y>=c.y&&a.y<=b.y)
{
if(a.x>b.x&&a.x<c.x&&a.y>c.y&&a.y<b.y) return ;
return ;
}
return -;
}
int main()
{
//freopen("a.txt","r",stdin);
int n,area;
while(~scanf("%d",&n)&&n)
{
if(n<) {printf("imp\n");continue;}
set<point>s;
// set<point>::iterator it;
int maxn=,cnt=;
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
s.insert(p[i]);
}
sort(p+,p+n+);
/*for(it=s.begin();it!=s.end();it++)
{
point t=*it;
printf("%d %d\n",t.x,t.y);
}*/
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
if(p[i].x<p[j].x&&p[i].y<p[j].y) //枚举出第一个矩形
{
q1.x=p[i].x;q1.y=p[j].y;
if(!s.count(q1))continue;
q2.x=p[j].x;q2.y=p[i].y;
if(!s.count(q2))continue;
for(int l=;l<=n;l++)
{
for(int k=l+;k<=n;k++)
{
if(p[l].x<p[k].x&&p[l].y<p[k].y)//第二个矩形
{
q3.x=p[l].x;q3.y=p[k].y;
if(!s.count(q3))continue;
q4.x=p[k].x;q4.y=p[l].y;
if(!s.count(q4))continue;
if(i==l||j==l||i==k||j==k)continue; //防止坐标重复
if(q3.x==p[i].x&&q3.y==p[i].y||q3.x==p[j].x&&q3.x==p[j].y) continue;
if(q4.x==p[i].x&&q4.y==p[i].y||q4.x==p[j].x&&q4.x==p[j].y) continue; int x1=check(p[i],q3,q4);
int x2=check(p[j],q3,q4);
int x3=check(q1,q3,q4);
int x4=check(q2,q3,q4); //判断在矩形内部还是边界
if(x1==&&x2==&&x3==&&x4==) //内含
{
// printf("%d %d %d %d\n",q1.x,q1.y,q2.x,q2.y);
area=abs(q4.x-q3.x)*abs(q3.y-q4.y);
if(area>maxn) maxn=area;
//printf("%d\n",area);
cnt=;
}
else if(x1==||x2==||x3==||x4==)continue; //相交
else if(x1==-&&x2==-&&x3==-&&x4==-) //枚举 另一种情况
{
//printf("%d\n",1);
int y1=check(p[l],q1,q2);
int y2=check(p[k],q1,q2);
int y3=check(q3,q1,q2);
int y4=check(q4,q1,q2);
//printf("%d\n",ans);
// printf("%d %d %d %d\n",q1.x,q1.y,q2.x,q2.y);
// printf("%d %d %d %d\n",q3.x,q3.y,q4.x,q4.y);
if(y1==||y2==||y3==||y4==) continue;
else if(y1==&&y2==&&y3==&&y4==)
{
area=abs(q2.x-q1.x)*abs(q1.y-q2.y);
if(area>maxn) maxn=area;
cnt=;
}
else if(y1==-&&y2==-&&y3==-&&y4==-)
{
// printf("%d %d %d %d\n",q1.x,q1.y,q2.x,q2.y);
//printf("%d %d %d %d\n",q3.x,q3.y,q4.x,q4.y);
area=abs(q2.x-q1.x)*abs(q1.y-q2.y)+abs(q4.x-q3.x)*abs(q3.y-q4.y);
// printf("%d\n",area);
if(area>maxn) maxn=area;
cnt=;
}
}
}
}
}
}
}
}
if(!cnt) printf("imp\n");
else
printf("%d\n",maxn);
}
return ;
}
hdu - 5128 The E-pang Palace(枚举+计算几何)的更多相关文章
- 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个点,选出其中8个点组成两个矩形,使得两个矩形的面积和最大. 思路:找出所有的矩形,然后枚举, ...
- hdu 1882 Strange Billboard(位运算+枚举)
http://acm.hdu.edu.cn/showproblem.php?pid=1882 感觉非常不错的一道题. 给一个n*m(1<=n,m<=16)的矩阵,每一个格子都有黑白两面,当 ...
- hdu 2105:The Center of Gravity(计算几何,求三角形重心)
The Center of Gravity Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 5128.The E-pang Palace-计算几何
The E-pang Palace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Othe ...
- HDU 1281——棋盘游戏——————【最大匹配、枚举删点、邻接表方式】
棋盘游戏 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status ...
- Hdu 5371 Hotaru's problem (manacher+枚举)
题目链接: Hdu 5371 Hotaru's problem 题目描述: 给出一个字符串N,要求找出一条N的最长连续子串.这个子串要满足:1:可以平均分成三段,2:第一段和第三段相等,3:第一段和第 ...
- Hdu 5358 First One (尺取法+枚举)
题目链接: Hdu 5358 First One 题目描述: 数组a有n个元素,S[i,j]定义为a[i]+a[i+1]+.....+a[j],问:这个死东西等于多少? 解题思路: 二分肯定超,这个题 ...
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...
随机推荐
- 在Servlet中使用@Autowire的方法
在你调用的Servlet中添加如下代码: public void init(ServletConfig config) { try { super.init(config); SpringBeanAu ...
- Types of Security Vulnerabilities
1)内存空间安全.2)参量级别数据安全:3)通信级别数据安全:4)数据访问控制:5)通信对象身份确认. https://developer.apple.com/library/content/docu ...
- Selenium3+python自动化008-操作浏览器基本方法
一.打开网站1.第一步:从selenium里面导入webdriver模块2.打开Firefox浏览器(Ie和Chrome对应下面的)3.打开百度网址二.页面刷新1.有时候页面操作后,数据可能没及时同步 ...
- python+Eclipse+pydev环境搭建1
编辑器: Eclipse + pydev插件 1. Eclipse是写JAVA的IDE, 这样就可以通用了,学习代价小. 学会了Eclipse, 以后写Python或者JAVA 都可以. 2. Ec ...
- 利用python库twilio来免费发送短信
大家好,我是四毛,最近开通了个人公众号“用Python来编程”,欢迎大家“关注”,这样您就可以收到优质的文章了. 今天跟大家分享的主题是利用python库twilio来免费发送短信. 先放一张成品图 ...
- nginx 集群
Nginx是什么? Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器.一直纳闷这个X是怎么来 ...
- PHP fpm配置和优化
pm.max_children = 1024 #最大子进程数 maximum number of child processes when pm is set to 'dynamic' or 'ond ...
- 5.12-leepcode 作业详解
leepcode 作业详解 1.给定一个整数数组,判断是否存在重复元素.如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 false. 正确解答 class So ...
- LeetCode(19) Remove Nth Node From End of List
题目 Given a linked list, remove the nth node from the end of list and return its head. For example, G ...
- laravel(4.2) +Zizaco
操作步骤:https://github.com/Zizaco/entrust/tree/1.0 这篇博客说的蛮详细的:http://blog.boolw.com/?p=241 简化后的步骤 1.在根项 ...