UVALive 7070 The E-pang Palace(暴力)
实话说这个题就是个暴力,但是有坑,第一次我以为相含是不行的,结果WA,我加上相含以后还WA,我居然把这两个矩形的面积加在一块了吗,应该取大的那一个啊……
方法就是枚举对角线,为了让自己不蒙圈,我写了一个矩阵类,可以实现自动判断是否能成功形成矩阵,自动排序四个点,返回面积,方便以后的判断。
C++面向对象大法好……
代码及注释如下:
#include<bits/stdc++.h>
using namespace std;
#define MaxN 55
#define MaxM 222
struct Pos{
int x,y;
void Set(int x1,int y1)
{
x = x1;
y = y1;
}
}p[MaxN];
int isp[MaxM][MaxM],n;
bool cmp(Pos a,Pos b){
if(a.x != b.x) return a.x < b.x;
return a.y < b.y;
}
class Rec{
public:
Pos k[];
int area;
bool Creat(Pos a,Pos b){
k[].x = a.x,k[].y = a.y;
k[].x = b.x,k[].y = b.y;
k[].x = a.x,k[].y = b.y;
k[].x = b.x,k[].y = a.y;
sort(k,k+,cmp);///排序便于判断
area = abs(a.x-b.x)*abs(a.y-b.y);
for(int i = ;i < ;i++){
int tx = k[i].x,ty = k[i].y;
if(isp[tx][ty]==) {
return false;
}
}
return true;
}
};
bool Equal(Pos a,Pos b){
return (a.x==b.x && a.y==b.y);
}
bool All_in(Pos a,Pos b,Pos c){
return (c.x>a.x && c.x<b.x && c.y>a.y && c.y<b.y);
}
bool Part_in(Pos a,Pos b,Pos c){
return (c.x>=a.x && c.x<=b.x && c.y>=a.y && c.y<=b.y);
}
int Check(Rec a,Rec b){
for(int i = ;i < ;i++){///判断重复点
if(Equal(a.k[i],b.k[i])) return ;
}
int tot1 = ,tot2 = ;
for(int i = ;i < ;i++){///先判断是否两个相含
if(All_in(a.k[],a.k[],b.k[i])) tot1++;
if(All_in(b.k[],b.k[],a.k[i])) tot2++;
}
if(tot1 == || tot2 == ) {
return ;
}
for(int i = ;i < ;i++){///不是相含,就必须相离
if(Part_in(a.k[],a.k[],b.k[i])) return ;
if(Part_in(b.k[],b.k[],a.k[i])) return ;
}
return ;
}
int Get_ans(){
int ans = -;
Rec a,b;
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) continue;
if(a.Creat(p[i],p[j]) == false) continue;
for(int k = ;k < n;k++)
{
for(int q = k+;q < n;q++)
{
if(p[k].x==p[q].x || p[k].y==p[q].y) continue;
if(b.Creat(p[k],p[q]) == false) continue;
int c = Check(a,b);
if(c == ) ans = max(ans,a.area+b.area);
if(c == ) ans = max(ans,max(a.area,b.area));
///相含的话,选择较大的面积
}
}
}
}
return ans;
}
int main()
{
// freopen("B.in.cpp","r",stdin);
int x,y;
while(cin>>n && n)
{
memset(isp,,sizeof(isp));
for(int i = ; i < n; i++)
{
cin>>x>>y;
p[i].Set(x,y);
isp[x][y] = ;
}
int ans = Get_ans();
if(ans == -) cout<<"imp"<<endl;
else cout<<ans<<endl;
}
return ;
}
UVALive 7070 The E-pang Palace(暴力)的更多相关文章
- UVALive 7070 The E-pang Palace 暴力
The E-pang Palace Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/problem ...
- 简单几何(判断矩形的位置) UVALive 7070 The E-pang Palace(14广州B)
题目传送门 题意:给了一些点,问组成两个不相交的矩形的面积和最大 分析:暴力枚举,先找出可以组成矩形的两点并保存起来(vis数组很好),然后写个函数判断四个点是否在另一个矩形内部.当时没有保存矩形,用 ...
- UVaLive 6855 Banks (水题,暴力)
题意:给定 n 个数,让你求最少经过几次操作,把所有的数变成非负数,操作只有一种,变一个负数变成相反数,但是要把左右两边的数加上这个数. 析:由于看他们AC了,时间这么短,就暴力了一下,就AC了... ...
- UVALive 2145 Lost in Space(暴力)
题目并不难,就是暴力,需要注意一下输出形式和精度. #include<iostream> #include<cstdio> #include<cmath> usin ...
- The E-pang Palace(暴力几何)
//暴力的几何题,问,n个点可以组成的矩形,不相交,可包含的情况下,最大的面积,还有就是边一定与 x y 轴平行,所以比较简单了 //暴力遍历对角线,搜出所有可能的矩形,然后二重循环所有矩形,判断一下 ...
- UVALive 6862 Triples (找规律 暴力)
Triples 题目链接: http://acm.hust.edu.cn/vjudge/contest/130303#problem/H Description http://7xjob4.com1. ...
- UVALive 7457 Discrete Logarithm Problem (暴力枚举)
Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...
- UVALive - 6837 Kruskal+一点性质(暴力枚举)
ICPC (Isles of Coral Park City) consist of several beautiful islands. The citizens requested constru ...
- HDU - 5128The E-pang Palace+暴力枚举,计算几何
第一次写计算几何,ac,感动. 不过感觉自己的代码还可以美化一下. 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意: 在一个坐标系中,有n个 ...
随机推荐
- C++把引用作为返回值
当返回一个引用时,要注意被引用的对象不能超出作用域.所以返回一个对局部变量的引用是不合法的,但是,可以返回一个对静态变量的引用. int& func() { int q; //! return ...
- Jdk 1.8*安装并配置
转载自:http://www.cnblogs.com/zlslch/p/5658399.html 简单说下,jdk1.8*的下载,见http://www.cnblogs.com/zlslch/p/5 ...
- edgerouter bonding
configure set interfaces bonding bond0 mode 802.3ad set interfaces ethernet eth1 bond-group bond0 se ...
- CentOS6.5 安装mysql5.6.30
1.下载解压由于系统会自带mysql5.1版本的数据库,需要卸载.[root@localhost src]# yum remove -y mysql-libs[root@localhost src]# ...
- 怎样取json对应的值
{ "轮胎1":[{"数量": "1","型号": "195 65R15","售价&quo ...
- push类型消息中间件-消息服务端(三)
1.连接管理 网络架构原来是使用是自己开发的网络框架Gecko,Gecko默认为每个网络连接分配64KB的内存,支持1000个网络连接,就需要大概64MB的内存.后来采用Netty重构了网络服务层. ...
- 设计模式 --迭代器模式(Iterator)
能够游走于聚合内的每一个元素,同时还可以提供多种不同的遍历方式. 基本概念: 就是提供一种方法顺序访问一个聚合对象中的各个元素,而不是暴露其内部的表示. 使用迭代器模式的优点: 遍历集合或者数 ...
- Java Web 开发环境快速搭建
Java Web 开发环境快速搭建 在因某种原因更换开发设备后,可依据此文快速搭建开发环境,恢复工作环境. Java开发环境: Windows 10 (64-bit) Oralce JDK Eclip ...
- Android实现图片宽度100%ImageView宽度且高度按比例自动伸缩
在ListView中为了实现图片宽度100%适应ImageView容器宽度,让高度自动按比例伸缩功能,查了很多资料,搞了一下午都没找出个现成的办法,不过貌似有个结论了,就是: Android自身不能实 ...
- Sublime Text 2
常用功能: 安装Package Control:https://sublime.wbond.net/ 多行选择.多行编辑鼠标选中多行,按下 Ctrl+Shift+L (Command+Shift+L) ...