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/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[][];
struct node
{
int x,y;
};
node p[];
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 ;
return ;
}
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 ;
return ;
}
int check(node a,node b,node c,node d)
{
node t1[],t2[];
t1[].x=min(a.x,b.x);t1[].y=min(a.y,b.y);
t1[].x=max(a.x,b.x);t1[].y=min(a.y,b.y);
t1[].x=min(a.x,b.x);t1[].y=max(a.y,b.y);
t1[].x=max(a.x,b.x);t1[].y=max(a.y,b.y); t2[].x=min(c.x,d.x);t2[].y=min(c.y,d.y);
t2[].x=max(c.x,d.x);t2[].y=min(c.y,d.y);
t2[].x=min(c.x,d.x);t2[].y=max(c.y,d.y);
t2[].x=max(c.x,d.x);t2[].y=max(c.y,d.y); for(int i=;i<;i++)
{
//cout<<t1[i].x<<" "<<t1[i].y<<endl;
if(mp[t1[i].x][t1[i].y]==)
return ;
} for(int i=;i<;i++)
{
//cout<<t2[i].x<<" "<<t2[i].y<<endl;
if(mp[t2[i].x][t2[i].y]==)
return ;
} if(t1[].x==t1[].x)return ;
if(t1[].y==t1[].y)return ;
if(t2[].x==t2[].x)return ;
if(t2[].y==t2[].y)return ; int flag = ;
for(int i=;i<;i++)
if(No_In(t1[i],t2[],t2[]))
flag++;
if(flag==)return (t2[].x-t2[].x)*(t2[].y-t2[].y); flag = ;
for(int i=;i<;i++)
if(No_In(t2[i],t1[],t1[]))
flag++;
if(flag==)return (t1[].x-t1[].x)*(t1[].y-t1[].y); for(int i=;i<;i++)
if(In(t1[i],t2[],t2[]))
return ;
for(int i=;i<;i++)
if(In(t2[i],t1[],t1[]))
return ; return (t2[].x-t2[].x)*(t2[].y-t2[].y) + (t1[].x-t1[].x)*(t1[].y-t1[].y);
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(mp,,sizeof(mp));
if(n==)break;
for(int i=;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
mp[p[i].x][p[i].y]=;
}
int ans = ;
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
for(int t=;t<=n;t++)
{
for(int k=t+;k<=n;k++)
{
if(i==t&&j==k)continue;
int Area = check(p[i],p[j],p[t],p[k]);
if(Area!=)
{
//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==)printf("imp\n");
else printf("%d\n",ans);
}
}
UVALive 7070 The E-pang Palace 暴力的更多相关文章
- UVALive 7070 The E-pang Palace(暴力)
实话说这个题就是个暴力,但是有坑,第一次我以为相含是不行的,结果WA,我加上相含以后还WA,我居然把这两个矩形的面积加在一块了吗,应该取大的那一个啊-- 方法就是枚举对角线,为了让自己不蒙圈,我写了一 ...
- 简单几何(判断矩形的位置) 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个 ...
随机推荐
- 域名下Web项目重定向出现DNS域名解析错误问题
问题: 项目使用的是阿里云的ESC,前几天为IP地址添加了域名 发现发送正常请求时跳转没问题,但发送重定向请求时,页面就会出现DNS域名解析错误的情况 1.我在Tomcat的server.xml中配置 ...
- SpringMVC——实现拦截器
1. SpringMVC拦截器的概念与Struts2相同 2. 实现拦截器 (1) 项目结构 (2) 实现HandlerInterceptor接口 package com.zhengbin.contr ...
- .NET Remoting
.NET Remoting .NET Remoting是微软早期的分布式通信技术,虽然微软后来通过WCF通用基础通信框架整合掉了,但是通过回顾学习Remoting,反过来学习理解WCF也是很有帮助 ...
- kettle实现文本文件数据抽取方法
KETTLE做调度的思路是,把一个有特定格式的的文本文件,写入ORACLE数据库表, 具体方法见如下操作: 首先来看下文本文件的内容: 1|test1 2|test2 3|test3 通过|进行分割的 ...
- linux命令——rmdir
rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.rm - r dir命令可代替rmdir rmdir [选项]... 目录... - p 递归删除目录dirname,当 ...
- Easy Climb
题意: 有n块石头,给定他们的高度,现保持第一和最后一块高度不变,其他可增加和减少高度,求通过变换使所有相邻石头的高度差的绝对值不大于d,所变化高度总和的最小值. 分析: 状态还可以想出来,dp[i] ...
- python的Requests模块使用tips
post方法提交的是表单,要用data放dict get方法请求的是参数,要用params放dict HTTP头部是大小写不敏感的
- 仿酷狗音乐播放器开发日志十九——CTreeNodeUI的bug修复二(附源码)
转载请说明原出处,谢谢 今天本来打算把仿酷狗播放列表的子控件拖动插入功能做一下,但是仔细使用播放列表控件时发现了几个逻辑错误,由于我的播放 列表控件是基于CTreeViewUI和CTreeNodeUI ...
- UML 学习
推荐书籍:<面向对象分析与设计(第3版)>.<UML精粹:标准对象建模语言简明指南(第3版)> 推荐一: http://amateras.sourceforge.jp/cgi- ...
- MEAN stack 做网站【1】
做一个小project,学习如何用MEAN技术栈来搭建网站. JavaScript新手,不足之处,请指出.(系统为win10) 搭建环境: 安装Node.JS (略过) 安装MySQL,MongoDB ...