http://acm.hdu.edu.cn/showproblem.php?pid=5128

题意:给定N个点,选出其中8个点组成两个矩形,使得两个矩形的面积和最大。

思路:找出所有的矩形,然后枚举,挑选求中的两个矩形,判断位置关系,符合条件求出他们的和最大值。坑点:可以内含,内含的时候计算外面的矩形的面积。

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int n;
struct node
{
int x,y;
bool operator <(const node &a) const
{
return (x<a.x)||(x==a.x&&y<a.y);
}
} p[],q[],f1[],f2[]; struct node1
{
int num[];
} c[]; int main()
{
//freopen("sss.txt","w",stdout);
while(scanf("%d",&n)!=EOF)
{
if(n==) break; for(int i=; i<=n; i++)
{
scanf("%d %d",&p[i].x,&p[i].y);
}
if(n<)
{
printf("imp\n");
continue;
}
sort(p+,p+n+);
int t1=;
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
if(i==j) continue;
for(int a=; a<=n; a++)
{
if(i==a||j==a) continue;
for(int b=; b<=n; b++)
{
if(i==b||j==b||a==b) continue;
q[]=p[i];
q[]=p[j];
q[]=p[a];
q[]=p[b];
sort(q,q+);
if(q[].x!=q[].x||q[].y!=q[].y||q[].x!=q[].x||q[].y!=q[].y)
{
continue;
}
if(q[].x!=q[].x&&q[].y!=q[].y)
{
c[t1].num[]=i;
c[t1].num[]=j;
c[t1].num[]=a;
c[t1++].num[]=b;
}
}
}
}
}
int ans=-;
for(int i=; i<t1; i++)
{
f1[]=p[c[i].num[]];
f1[]=p[c[i].num[]];
f1[]=p[c[i].num[]];
f1[]=p[c[i].num[]];
sort(f1,f1+);
for(int j=; j<t1; j++)
{
if(i==j) continue;
f2[]=p[c[j].num[]];
f2[]=p[c[j].num[]];
f2[]=p[c[j].num[]];
f2[]=p[c[j].num[]];
sort(f2,f2+);
bool flag=false;
for(int ii=; ii<; ii++)
{
for(int jj=; jj<; jj++)
{
if(p[c[i].num[ii]].x==p[c[j].num[jj]].x&&p[c[i].num[ii]].y==p[c[j].num[jj]].y)
{
flag=true;
break;
}
}
if(flag) break;
}
if(flag) continue;
if(f1[].x<=f2[].x&&f2[].x<=f1[].x&&f2[].y<=f1[].y&&f2[].y>=f1[].y&&f2[].x>=f1[].x)
{
continue;
}
if(f1[].x<=f2[].x&&f2[].x<=f1[].x&&f2[].y<=f1[].y&&f2[].y>=f1[].y&&f2[].x>=f1[].x)
{
continue;
}
if(f1[].x>=f2[].x&&f1[].x<=f2[].x&&f1[].y<=f2[].y&&f1[].y>=f2[].y&&f1[].x>=f2[].x)
{
continue;
}
if(f1[].x>=f2[].x&&f1[].x<=f2[].x&&f1[].y<=f2[].y&&f1[].y>=f2[].y&&f1[].x>=f2[].x)
{
continue;
}
if(f1[].x<=f2[].x&&f2[].x<=f1[].x&&f2[].y<=f1[].y&&f2[].y>=f1[].y&&f2[].y<=f1[].y)
{
continue;
}
if(f1[].x<=f2[].x&&f2[].x<=f1[].x&&f2[].y>=f1[].y&&f2[].y<=f1[].y&&f2[].y>=f1[].y)
{
continue;
}
if(f2[].x<=f1[].x&&f1[].x<=f2[].x&&f1[].y<=f2[].y&&f1[].y>=f2[].y&&f1[].y<=f2[].y)
{
continue;
}
if(f2[].x<=f1[].x&&f1[].x<=f2[].x&&f1[].y>=f2[].y&&f1[].y<=f2[].y&&f1[].y>=f2[].y)
{
continue;
}
int s=-;
if(f1[].x>f2[].x&&f1[].x<f2[].x&&f1[].y>f2[].y&&f1[].y<f2[].y)
{
s=(f2[].y-f2[].y)*(f2[].x-f2[].x);
}
else if(f2[].x>f1[].x&&f2[].x<f1[].x&&f2[].y>f1[].y&&f2[].y<f1[].y)
{
s=(f1[].y-f1[].y)*(f1[].x-f1[].x);
}
else
s=(f1[].y-f1[].y)*(f1[].x-f1[].x)+(f2[].y-f2[].y)*(f2[].x-f2[].x);
ans=max(ans,s);
}
}
if(ans==-) printf("imp\n");
else
printf("%d\n",ans);
}
return ;
}

hdu 5128 The E-pang Palace的更多相关文章

  1. HDU 5128 The E-pang Palace(2014广州赛区现场赛B题 计算几何)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5128 解题报告:在一个平面上给出n个点的坐标,用这n个点作为矩形的四个顶点,作两个矩形,要求两个矩形不 ...

  2. hdu - 5128 The E-pang Palace(枚举+计算几何)

    http://acm.hdu.edu.cn/showproblem.php?pid=5128 给出n个点,求n个点组成两个矩形的最大面积. 矩形必须平行x轴,并且不能相交,但是小矩形在大矩形内部是可以 ...

  3. hdu 5129 (枚举) The E-pang Palace

    题目;http://acm.hdu.edu.cn/showproblem.php?pid=5128. 给你n个点,问能否组成两个不相交的与坐标轴平行的矩形,能就输出两矩形的面积和,不能就输出一个字符串 ...

  4. HDU 5128.The E-pang Palace-计算几何

    The E-pang Palace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Othe ...

  5. HDU 5218 The E-pang Palace (简单几何—2014广州现场赛)

    题目链接:pid=5128">http://acm.hdu.edu.cn/showproblem.php? pid=5128 题面: The E-pang Palace Time Li ...

  6. HDU - 5128The E-pang Palace+暴力枚举,计算几何

    第一次写计算几何,ac,感动. 不过感觉自己的代码还可以美化一下. 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意: 在一个坐标系中,有n个 ...

  7. HDU 4435 charge-station () bfs图论问题

    E - charge-station Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  8. HDU 4435 charge-station bfs图论问题

    E - charge-station Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  9. HDU 5025:Saving Tang Monk(BFS + 状压)

    http://acm.hdu.edu.cn/showproblem.php?pid=5025 Saving Tang Monk Problem Description   <Journey to ...

随机推荐

  1. tcpdump抓包以及port查看的一些操作

    1.tcpdump. nginx开启后会占用80端口,此时运行命令:tcpdump tcp port 80 结果例如以下: [syswj@host ~]$ sudo tcpdump tcp port ...

  2. 《Linux内核分析》-----张超

    http://www.cnblogs.com/zhangchao0515/category/797954.html MOOC课程 http://mooc.study.163.com/course/US ...

  3. easy ui example

    http://www.jeasyui.com/tutorial/index.php http://www.w3cschool.cc/jeasyui/jqueryeasyui-tutorial.html

  4. FtpClient中文乱码问题解决

    最近在做文件服务器的相关东西,在原有的磁盘存储的基础上,增加了Ftp的存储方式,客户端选用的是Apache的FtpClient.  今天在测试的时候,发现中文的路径后者文件名不支持,查阅了相关资料后终 ...

  5. common-lang——StringUtils

    1.文字省略处理 最多显示几个字 StringUtils.abbreviate("中华人民共和国", 5); // output:中华.. 2.文字中间省略 最多显示几个字符 St ...

  6. win 10 安装 mysql解压版 步骤

    参考资料:win 10 安装 mysql 5.7 网址:http://blog.sina.com.cn/s/blog_5f39af320102wbk0.html 本文参考上面的网址的教程,感谢作者分享 ...

  7. linux 简单命令

    很久没有接触linux了,很多命令也忘记了,现在自己独立安装一个linux,独立安装LAMP,让自己记录下来这段. 怎么进入命令行 init 3, 回到桌面 init 5在不是root用户情况下,切换 ...

  8. PHP 通过随机数获得ASCII 值返回字符。

    for($i=0;$i<20;$i++){ $Matrix .= chr(65 + rand(0,26)); }

  9. MVC中javascript直接调用Model

    最近做一个统计页面, Model从后台已经获取了数据集合,想直接在前台展示,而这个展示是需要用js生成图表的. 控制器部分代码: public ActionResult Index() { var m ...

  10. Ubuntu Server 14.04 下root无法ssh登陆

    今天安装了Ubuntu Server 14.04   在终端配置了root密码后,使用SecureCRT和putty竟然不能ssh登陆,SecureCRT一直提示密码不对,但是可以肯定输入的密码100 ...