[hdu5251]矩形面积 旋转卡壳求最小矩形覆盖
旋转卡壳求最小矩形覆盖的模板题。
因为最小矩形必定与凸包的一条边平行,则枚举凸包的边,通过旋转卡壳的思想去找到其他3个点,构成矩形,求出最小面积即可。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<time.h>
#include<cstdlib>
#include<cmath>
#include<list>
using namespace std;
#define MAXN 100100
#define eps 1e-9
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Fore(i,a,b) for(int i=a;i>=b;i--)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mkp make_pair
#define pb push_back
#define cr clear()
#define sz size()
#define met(a,b) memset(a,b,sizeof(a))
#define iossy ios::sync_with_stdio(false)
#define fre freopen
#define pi acos(-1.0)
#define inf 1e6+7
#define Vector Point
const int Mod=1e9+;
typedef unsigned long long ull;
typedef long long ll;
int dcmp(double x){
if(fabs(x)<=eps) return ;
return x<?-:;
}
struct Point{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
bool operator < (const Point &a)const{
if(x==a.x) return y<a.y;
return x<a.x;
}
Point operator - (const Point &a)const{
return Point(x-a.x,y-a.y);
}
Point operator + (const Point &a)const{
return Point(x+a.x,y+a.y);
}
Point operator * (const double &a)const{
return Point(x*a,y*a);
}
Point operator / (const double &a)const{
return Point(x/a,y/a);
}
void read(){
scanf("%lf%lf",&x,&y);
}
void out(){
cout<<"debug: "<<x<<" "<<y<<endl;
}
bool operator == (const Point &a)const{
return dcmp(x-a.x)== && dcmp(y-a.y)==;
}
};
double Dot(Vector a,Vector b) {
return a.x*b.x+a.y*b.y;
}
double dis(Vector a) {
return sqrt(Dot(a,a));
}
double Cross(Point a,Point b){
return a.x*b.y-a.y*b.x;
}
int ConvexHull(Point *p,int n,Point *ch){
int m=;
For(i,,n-) {
while(m> && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
int k=m;
Fore(i,n-,){
while(m>k && Cross(ch[m-]-ch[m-],p[i]-ch[m-])<=) m--;
ch[m++]=p[i];
}
if(n>) m--;
return m;
}
double ANS(Point *p,int n){
int L,R=,U=;
double ans=1e9+;
p[n]=p[];
For(i,,n-) {
while(Cross(p[i+]-p[i],p[U+]-p[i])>=Cross(p[i+]-p[i],p[U]-p[i])) U=(U+)%n;
while(Dot(p[i+]-p[i],p[R+]-p[i])>Dot(p[i+]-p[i],p[R]-p[i])) R=(R+)%n;
if(!i) L=R;
while(Dot(p[i+]-p[i],p[L+]-p[i])<=Dot(p[i+]-p[i],p[L]-p[i])) L=(L+)%n;
double tmp=fabs(Cross(p[U]-p[i],p[i+]-p[i]))/dis(p[i+]-p[i]);
double cnt1=fabs(Dot(p[L]-p[i],p[i+]-p[i]))/dis(p[i+]-p[i]),cnt2=fabs(Dot(p[R]-p[i],p[i+]-p[i]))/dis(p[i+]-p[i]);
ans=min(ans,(cnt2+cnt1)*tmp);
}
return ans;
}
int n,m;
Point p[];
Point ch[];
void solve(){
scanf("%d",&n);
int rt=;
For(i,,n-) {
p[rt++].read();
p[rt++].read();
p[rt++].read();
p[rt++].read();
}
sort(p,p+rt);
m=ConvexHull(p,rt,ch);
printf("%.0lf\n",ANS(ch,m));
}
int main(){
// fre("in.txt","r",stdin);
int t=;
cin>>t;
For(i,,t) printf("Case #%d:\n",i),solve();
return ;
}
[hdu5251]矩形面积 旋转卡壳求最小矩形覆盖的更多相关文章
- HDU 5251 矩形面积 (旋转卡壳)
2015年百度之星程序设计大赛 - 初赛(1) 1006 比赛链接:2015年百度之星程序设计大赛 - 初赛(1) 题目链接:HDU 5251 Problem Description 小度熊有一个桌面 ...
- TZOJ 2392 Bounding box(正n边形三点求最小矩形覆盖面积)
描述 The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located ...
- POJ 2079 Triangle 旋转卡壳求最大三角形
求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...
- UVa 1453 - Squares 旋转卡壳求凸包直径
旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...
- poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方
旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...
- POJ2187 旋转卡壳 求最长直径
给定平面上的一些散点集,求最远两点距离的平方值. 题解: 旋转卡壳求出凸包,然后根据单调性,求出最远两点的最大距离 #pragma GCC optimize(2) #pragma G++ optimi ...
- bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包
[HNOI2007]最小矩形覆盖 Time Limit: 10 Sec Memory Limit: 162 MBSec Special JudgeSubmit: 2081 Solved: 920 ...
- bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积
在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...
- hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)
链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS Memory Limit: 30000K Total Submissio ...
随机推荐
- jdk的keystore生成
使用jdk路径下的keytool.exe生成 生成证书: 导出证书,此时输入生成证书时设置的密码:
- [Ctsc2014]企鹅QQ
3555: [Ctsc2014]企鹅QQ Time Limit: 20 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description P ...
- 部署维护docker环境
其实前面已经用salt,安装部署了docker应用环境了,过程中还是遇到了不少问题,所以这里再相对仔细的记录一下,docker手机安装过程应注意的事情 安装过程部分参考了刘天斯大师文档部署 1,安装环 ...
- 初学者必看:.NET 中的静态与非静态的异同
对于初学者来说,.NET 的静态和非静态一直比较难掌握,这里做一个总结,介绍静态类和普通类,静态方法和实例方法,静态构造函数和实例构造函数,静态字段和非静态字段的区别. 静态类 vs 普通类 静态类与 ...
- 【CodeForces】713 C. Sonya and Problem Wihtout a Legend
[题目]C. Sonya and Problem Wihtout a Legend [题意]给定n个数字,每次操作可以对一个数字±1,求最少操作次数使数列递增.n<=10^5. [算法]动态规划 ...
- datagrid导出数据
//导出excel public function touzi_doExport() { $search=$_POST['search']; //接受前端传过来的数据 $this->succes ...
- SDUT 3929
Description 蓝色空间号和万有引力号进入了四维水洼,发现了四维物体--魔戒. 这里我们把飞船和魔戒都抽象为四维空间中的一个点,分别标为 "S" 和 "E&quo ...
- CRF++进行中文分词实例
工具包:https://taku910.github.io/crfpp/#tips 语料:http://sighan.cs.uchicago.edu/bakeoff2005/ 安装: 1)下载linu ...
- Lucene7.2.1系列(二)luke使用及索引文档的基本操作
系列文章: Lucene系列(一)快速入门 Lucene系列(二)luke使用及索引文档的基本操作 Lucene系列(三)查询及高亮 luke入门 简介: github地址:https://githu ...
- webpack中的静态资源处理
你可能已经注意到,在我们的项目结构里,有两个静态文件的路径,分别是:src/assets 和 static/.那这两个到底有什么区别呢? Webpacked 资源 为了回答这个问题,我们首先需要理解w ...