题目链接:

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

pid=5128

题面:

The E-pang Palace

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 512000/512000 K (Java/Others)

Total Submission(s): 1646    Accepted Submission(s): 1226

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
题目大意:

    给定一些点。要以这些点为四个顶点构造矩形,求构造两个矩形不相交(相交关系见图示)。且面积最大。

不可能则输出imp。


解题:

比較暴力就好,有点类似上周BC的一道题的做法,直接枚举两个对角线点,然后看另外两个点是否存在,存在的话。继续和还有一个矩形推断相对位置关系。

可是要小心一个矩形包括在另外一个矩形中,也是能够的,面积仅仅算大的那个。具体看代码。

代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
struct point
{
int x,y;
}store[35];
bool map[210][210];
int max(int a,int b)
{
return a>b?a:b;
}
int min(int a,int b)
{
return a<b? a:b;
}
int judge(int a,int b,int c,int d)
{
int res;
//下面分别为两个矩形左下和右上位置坐标
int lx1,lx2,ly1,ly2,rx1,rx2,ry1,ry2;
lx1=min(store[a].x,store[b].x);
ly1=min(store[a].y,store[b].y);
lx2=min(store[c].x,store[d].x);
ly2=min(store[c].y,store[d].y);
rx1=max(store[a].x,store[b].x);
ry1=max(store[a].y,store[b].y);
rx2=max(store[c].x,store[d].x);
ry2=max(store[c].y,store[d].y);
//是同一个矩形
if(lx1==lx2&&ly1==ly2&&rx1==rx2&&ry1==ry2)
return 0;
//一个全然在另外一个上面或者右边,那么就是两个矩形加
if((ry1<ly2)||(ry2<ly1)||(lx1>rx2)||(lx2>rx1))
{
res=(rx1-lx1)*(ry1-ly1)+(rx2-lx2)*(ry2-ly2);
return res;
}
//假设一个全然包括在另外一个里面
if(lx2<lx1&&ly2<ly1&&rx1<rx2&&ry1<ry2)
{
res=(rx2-lx2)*(ry2-ly2);
return res;
}
//假设一个全然包括在另外一个里面
if(lx1<lx2&&ly1<ly2&&rx2<rx1&&ry2<ry1)
{
res=(rx1-lx1)*(ry1-ly1);
return res;
}
//否则即为相交
else
return 0;
}
int main()
{
int n,a,b,c,d,e,f,g,h;
int area;
while(scanf("%d",&n)&&n)
{
area=0;
memset(map,0,sizeof(map));
//读入
for(int i=0;i<n;i++)
{
scanf("%d%d",&store[i].x,&store[i].y);
//将地图上对应的点标记为有
map[store[i].x][store[i].y]=1;
}
//没8个点,就肯定不行
if(n<8)
{
printf("imp\n");
continue;
}
else
{
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
//由于枚举的是对角线。所以在一条边上就跳过
if((store[i].x==store[j].x)||(store[i].y==store[j].y))
continue;
else
{
a=store[i].x;
b=store[i].y;
c=store[j].x;
d=store[j].y;
//假设除了对角线之外,另外两点存在
if(map[c][b]&&map[a][d])
{
for(int k=0;k<n-1;k++)
{
//不与原来两点反复
if((k!=i)&&(k!=j))
{
for(int m=k+1;m<n;m++)
{
//不与原来两点反复
if((m!=i)&&(m!=j))
{
//仅仅枚举对角线
if((store[k].x==store[m].x)||(store[k].y==store[m].y))
continue;
else
{
e=store[k].x;
f=store[k].y;
g=store[m].x;
h=store[m].y;
//假设除了对角线之外。另外两点存在,这时才推断两个矩形关系
if(map[g][f]&&map[e][h])
{
area=max(area,judge(i,j,k,m));
}
}
}
}
}
}
}
else
continue;
}
}
}
if(area==0)
printf("imp\n");
else
printf("%d\n",area);
}
}
return 0;
}

HDU 5218 The E-pang Palace (简单几何—2014广州现场赛)的更多相关文章

  1. hdu 5137 去掉一个点 使得最短路最大(2014广州现场赛 K题)

    题意:从2~n-1这几个点中任意去掉一个点,使得从1到n的最短路径最大,如果任意去掉一个点1~n无通路输出Inf. Sample Input4 51 2 31 3 71 4 502 3 43 4 23 ...

  2. hdu 5131 (2014广州现场赛 E题)

    题意:对给出的好汉按杀敌数从大到小排序,若相等,按字典序排.M个询问,询问名字输出对应的主排名和次排名.(排序之后)主排名是在该名字前比他杀敌数多的人的个数加1,次排名是该名字前和他杀敌数相等的人的个 ...

  3. HDU 4815 Little Tiger vs. Deep Monkey(2013长春现场赛C题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4815 简单的DP题. #include <stdio.h> #include <st ...

  4. hdu 5071(2014鞍山现场赛B题,大模拟)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 思路:模拟题,没啥可说的,移动的时候需要注意top的变化. #include <iostr ...

  5. hdu 5078 2014鞍山现场赛 水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5078 现场最水的一道题 连排序都不用,由于说了ti<ti+1 //#pragma comment(link ...

  6. HDU 4793 Collision (解二元一次方程) -2013 ICPC长沙赛区现场赛

    题目链接 题目大意 :有一个圆硬币半径为r,初始位置为x,y,速度矢量为vx,vy,有一个圆形区域(圆心在原点)半径为R,还有一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬 ...

  7. hdu 5078(2014鞍山现场赛 I题)

    数据 表示每次到达某个位置的坐标和时间 计算出每对相邻点之间转移的速度(两点间距离距离/相隔时间) 输出最大值 Sample Input252 1 9//t x y3 7 25 9 06 6 37 6 ...

  8. hdu 5120(求两个圆环相交的面积 2014北京现场赛 I题)

    两个圆环的内外径相同 给出内外径 和 两个圆心 求两个圆环相交的面积 画下图可以知道 就是两个大圆交-2*小圆与大圆交+2小圆交 Sample Input22 30 00 02 30 05 0 Sam ...

  9. hdu 5122 (2014北京现场赛 K题)

    把一个序列按从小到大排序 要执行多少次操作 只需要从右往左统计,并且不断更新最小值,若当前数为最小值,则将最小值更新为当前数,否则sum+1 Sample Input255 4 3 2 155 1 2 ...

随机推荐

  1. CentOS7 搭建Kafka(一)zookeeper篇

    CentOS7 搭建Kafka(一)zookeeper篇 近几年当红小生Kafka备受各路英雄好汉追捧,一点不比老前辈RabbitMQ和ActiveMQ差,因为流行,所以你就得学啊:我这么懒,肯定是不 ...

  2. C - New Year Candles

    Problem description Vasily the Programmer loves romance, so this year he decided to illuminate his r ...

  3. python 字符编码的两种方式写法:# coding=utf-8和# -*- coding:utf-8 -*-

    python运行文件是总会出现乱码问题,为了解决这个问题,在文件开头加上: # coding=utf-8 或者 # -*- coding:utf-8  -*- # coding=<encodin ...

  4. Run as ant build每次都执行两次

    因为用了selenium+testng+ant的框架,所以每次执行自动化,我就run as ant build.发现测试每次都执行两次,很奇怪.因为也没有影响到测试结果,所以一开始也就let it g ...

  5. .net中实现aspnetpager分页

    第一步首先导入aspnetpager控件,然后再把他从工具箱中拖出,代码如下:  <webdiyer:AspNetPager ID="aspnetpager1" runat= ...

  6. Android引导页

    源码地址:https://github.com/myloften/IntroSliderSample 博客地址:http://blog.csdn.net/loften_93663469/article ...

  7. 联想笋尖S90(S90-t 、S90-u)解锁BootLoader

    工具下载链接: http://pan.baidu.com/s/1eSgZuka 备用下载链接: http://pan.baidu.com/s/1dFKqSId 本篇教程,仅限于联想笋尖S90(S90- ...

  8. 利用set特性判断list是否存在重复的值

    List<String>  list2=new ArrayList();//存放很多值的list //根据set不能存储相同的值该特性来判断list2中的值是否重复 HashSet set ...

  9. [WIFI插座][阅读记录][SoC][RT5350] 00.目录 RALINK AP SDK 4.1.0.0 USER’s MANUAL

    来源是CSDN,百度网盘下载地址 http://pan.baidu.com/share/link?shareid=3504767505&uk=3426044377   授权声明,略过 免责声明 ...

  10. 图方法:寻找无向图联通子集的JAVA版本

    图像处理中一般使用稠密方法,即对图像进行像素集合进行处理.在图像拓扑方面,更多地应用图计算方法. 寻找无向图联通子集的JAVA版本,代码: //查找无向图的所有连通子集//wishchin!!! pu ...