The E-pang Palace

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=217902

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 magnicent 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 ght 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 re lasted
for more than three months, renouncing the end of Qin dynasty.
Several years later, Liu Bang defeated Xiangyu and became the rst 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 gures below shows 3 situations which are not qualied (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 rst 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 qualied 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

HINT

题意

平面给你n个点,让你找到两个和坐标轴平行的矩形,然后要求这两个矩形要么内含,要么相离

然后输出能够组成的最大面积

题解:

首先我们枚举矩形,只用n^2枚举就好了

只用枚举对角线,然后枚举之后,我们就暴力去判断就好了

判断两种情况,想清楚了,还是很简单的

代码:

#include<iostream>
#include<stdio.h>
#include<iostream>
#include<cstring>
using namespace std;int mp[250][250];
struct node
{int x,y;
};
node p[34];
int In(node a,node c,node b)
{if(a.x<=b.x&&a.x>=c.x&&a.y<=b.y&&a.y>=c.y)return 1;return 0;
}
int No_In(node a,node c,node b)
{if(a.x<b.x&&a.x>c.x&&a.y<b.y&&a.y>c.y)return 1;return 0;
}
int check(node a,node b,node c,node d)
{node t1[4],t2[4];t1[0].x=min(a.x,b.x);t1[0].y=min(a.y,b.y);t1[1].x=max(a.x,b.x);t1[1].y=min(a.y,b.y);t1[2].x=min(a.x,b.x);t1[2].y=max(a.y,b.y);t1[3].x=max(a.x,b.x);t1[3].y=max(a.y,b.y);t2[0].x=min(c.x,d.x);t2[0].y=min(c.y,d.y);t2[1].x=max(c.x,d.x);t2[1].y=min(c.y,d.y);t2[2].x=min(c.x,d.x);t2[2].y=max(c.y,d.y);t2[3].x=max(c.x,d.x);t2[3].y=max(c.y,d.y);for(int i=0;i<4;i++){//cout<<t1[i].x<<" "<<t1[i].y<<endl;if(mp[t1[i].x][t1[i].y]==0)return 0;}for(int i=0;i<4;i++){//cout<<t2[i].x<<" "<<t2[i].y<<endl;if(mp[t2[i].x][t2[i].y]==0)return 0;}if(t1[0].x==t1[1].x)return 0;if(t1[0].y==t1[2].y)return 0;if(t2[0].x==t2[1].x)return 0;if(t2[0].y==t2[2].y)return 0;int flag = 0;for(int i=0;i<4;i++)if(No_In(t1[i],t2[0],t2[3]))flag++;if(flag==4)return (t2[3].x-t2[0].x)*(t2[3].y-t2[0].y);flag = 0;for(int i=0;i<4;i++)if(No_In(t2[i],t1[0],t1[3]))flag++;if(flag==4)return (t1[3].x-t1[0].x)*(t1[3].y-t1[0].y);for(int i=0;i<4;i++)if(In(t1[i],t2[0],t2[3]))return 0;for(int i=0;i<4;i++)if(In(t2[i],t1[0],t1[3]))return 0;return (t2[3].x-t2[0].x)*(t2[3].y-t2[0].y) + (t1[3].x-t1[0].x)*(t1[3].y-t1[0].y);
}
int main()
{int n;while(scanf("%d",&n)!=EOF){memset(mp,0,sizeof(mp));if(n==0)break;for(int i=1;i<=n;i++){scanf("%d%d",&p[i].x,&p[i].y);mp[p[i].x][p[i].y]=1;}int ans = 0;for(int i=1;i<=n;i++){for(int j=i+1;j<=n;j++){for(int t=1;t<=n;t++){for(int k=t+1;k<=n;k++){if(i==t&&j==k)continue;int Area = check(p[i],p[j],p[t],p[k]);if(Area!=0){//printf("%d %d %d %d %d %d %d %d\n",p[i].x,p[i].y,p[j].x,p[j].y,p[t].x,p[t].y,p[k].x,p[k].y);//cout<<Area<<endl;
                        }ans = max(ans,Area);}}}}if(ans==0)printf("imp\n");else printf("%d\n",ans);}
}

UVALive 7070 The E-pang Palace 暴力相关推荐

  1. The E-pang Palace(暴力几何)

    //暴力的几何题,问,n个点可以组成的矩形,不相交,可包含的情况下,最大的面积,还有就是边一定与 x y 轴平行,所以比较简单了 //暴力遍历对角线,搜出所有可能的矩形,然后二重循环所有矩形,判断一下 ...

  2. 【爆炸总结】NOIp2017赛(Bao)后(Zha)总结

    题记 NOIp2017NOIp2017的闭幕让我感到一丝仓促,还未准备好迎接已经爆掉的惨不忍睹的分数. 一瞥 Day1Day1 t1t1 题目大意: 给出互质正整数a.ba.b,求最大的正整数kk,没 ...

  3. HDU5128The E-pang Palace(计算几何暴力枚举)

    The E-pang Palace 题解:预处理出所有矩形,然后枚举满足情况的两两矩形即可.因为是矩形,所以我们只需要存对角的两个点即可.就是要注意嵌套也是满足的. 代码 #include<bi ...

  4. 【暴力】UVALive - 4882 - Parenthesis

    就不断地扫整个序列,如果发现多余的括号就删除.大概复杂度还是O(n²)左右.如何判断不合法请详见代码. To a computer, there is no difference between th ...

  5. UVALive - 7511 Multiplication Table(暴力+模拟)

    题目链接:点击查看 题目大意:给出一个二维矩阵表示无限大的乘法表,每个位置的值都等于 i * j ,现在给出一个 n * m 的矩阵,现在需要判断该矩阵是否为乘法表的一个子矩阵 题目分析:训练时以为是 ...

  6. HDU 5128 The E-pang Palace 【暴力】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意:给出N个点,由这些点构成两个矩形,矩形是平行于x轴的,而且不能相交不能相邻(共用同一边), ...

  7. hdu 5128 The E-pang Palace (有技巧的暴力)

    this question can be find here I 've done this question twice and I didn't make it the last time and ...

  8. UVALive 7279 Sheldon Numbers (暴力打表)

    Sheldon Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/H Description According t ...

  9. UVaLive 4868 Palindrometer (暴力 / 构造)

    题意: 给定一个固定长度的字符串, 字符串是一个含有前导0的数字, 问这个数字加上多少能构成一个回文字符串. 分析: 其实这题有很多种方法, 方法12是我做完后看别人代码总结的, 方法3是我当时想的一 ...

最新文章

  1. Spark技术在京东智能供应链预测的应用——按照业务进行划分,然后利用scikit learn进行单机训练并预测...
  2. 【大学课程】操作系统知识点
  3. WampServer的研究日记二
  4. JVM调优之jstack找出最耗cpu的线程并定位代码
  5. 菜鸟网络宣布推出物流加速上云行动“鲲鹏计划”
  6. 判断一棵树是否为完全二叉树的算法c语言_[二叉树的面试算法](六)之二叉树结构判断-相关题型总结(4题)...
  7. C++之强制转换const_cast、static_cast、dynamic_cast、reinterpret_cast 、dynamic_cast
  8. 机电传动控制 第一周作业
  9. C# 客服端上传文件与服务器器端接收 (简单代码)
  10. 关于||逻辑或运算符运算符
  11. diff git 代码实现_Git比对文件之间的差异
  12. Java 大地坐标转经纬度,经纬度与WGS84坐标转换
  13. 聚沙成塔,亚马逊云科技为智能汽车创新加速
  14. npm install没有node_文件,并且package.json文件缺失
  15. P4556 [Vani有约会]雨天的尾巴 树链剖分 线段树合并
  16. 百度搜索结果的URL参数 搜索历史记录(rsv_sug)
  17. 【WPS】WPS之如何给文件加密?
  18. eNSP构建企业私有网络
  19. JS中常见的 “Uncaught TypeError: XXXX is not a function” 错误解析
  20. 2018-决策树约束的建筑点云提取方法

热门文章

  1. 三星a5009Android6.0,三星A5009原版系统刷机包_三星A5009最新升级包线刷包和root
  2. c语言switch不允许实型,C语言中switch语句什么意思
  3. bootstrap 时间线_股票配资均量线的实战用法绝技是什么?怎么用它判断买卖点?...
  4. 大学计算机专业副修课,计算机学院举行本科课程教学大纲修订工作研讨会
  5. Docker初学1:初识Docker
  6. mysql thread safe_Windows环境下完全手工配置Apache、MySQL和PHP(Thread Safe)
  7. elasticsearch 文档操作
  8. 设置tabbaritem的title的颜色及按钮图片
  9. iOS开发业界毒瘤 Hook
  10. lombox的用法(省去了set/get/NoArgsConstructor/AllArgsConstructor)