旋转卡壳求最小矩形覆盖的模板题。

  因为最小矩形必定与凸包的一条边平行,则枚举凸包的边,通过旋转卡壳的思想去找到其他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]矩形面积 旋转卡壳求最小矩形覆盖的更多相关文章

  1. HDU 5251 矩形面积 (旋转卡壳)

    2015年百度之星程序设计大赛 - 初赛(1) 1006 比赛链接:2015年百度之星程序设计大赛 - 初赛(1) 题目链接:HDU 5251 Problem Description 小度熊有一个桌面 ...

  2. TZOJ 2392 Bounding box(正n边形三点求最小矩形覆盖面积)

    描述 The Archeologists of the Current Millenium (ACM) now and then discover ancient artifacts located ...

  3. POJ 2079 Triangle 旋转卡壳求最大三角形

    求点集中面积最大的三角形...显然这个三角形在凸包上... 但是旋转卡壳一般都是一个点卡另一个点...这种要求三角形的情况就要枚举底边的两个点 卡另一个点了... 随着底边点的递增, 最大点显然是在以 ...

  4. UVa 1453 - Squares 旋转卡壳求凸包直径

    旋转卡壳求凸包直径. 参考:http://www.cppblog.com/staryjy/archive/2010/09/25/101412.html #include <cstdio> ...

  5. poj 2187 Beauty Contest , 旋转卡壳求凸包的直径的平方

    旋转卡壳求凸包的直径的平方 板子题 #include<cstdio> #include<vector> #include<cmath> #include<al ...

  6. POJ2187 旋转卡壳 求最长直径

    给定平面上的一些散点集,求最远两点距离的平方值. 题解: 旋转卡壳求出凸包,然后根据单调性,求出最远两点的最大距离 #pragma GCC optimize(2) #pragma G++ optimi ...

  7. bzoj1185 [HNOI2007]最小矩形覆盖 旋转卡壳求凸包

    [HNOI2007]最小矩形覆盖 Time Limit: 10 Sec  Memory Limit: 162 MBSec  Special JudgeSubmit: 2081  Solved: 920 ...

  8. bzoj1069: [SCOI2007]最大土地面积 凸包+旋转卡壳求最大四边形面积

    在某块平面土地上有N个点,你可以选择其中的任意四个点,将这片土地围起来,当然,你希望这四个点围成的多边形面积最大. 题解:先求出凸包,O(n)枚举旋转卡壳,O(n)枚举另一个点,求最大四边形面积 /* ...

  9. hdu 3934&&poj 2079 (凸包+旋转卡壳+求最大三角形面积)

    链接:http://poj.org/problem?id=2079 Triangle Time Limit: 3000MS   Memory Limit: 30000K Total Submissio ...

随机推荐

  1. JVM学习十:JVM之垃圾收集器及GC参数

    接近两个月左右没有写博客,主要是因为小孩过来后,回家比较忙,现在小孩端午送回家了,开始继续之前的JVM学习之路,前面学习了GC的算法和种类,那么本章则是基于算法来产生实际的用途,即垃圾收集器. 一.堆 ...

  2. CSS浏览器兼容问题集-第二部分

    11.高度不适应 高度不适应是当内层对象的高度发生变化时外层高度不能自动进行调节,特别是当内层对象使用margin 或paddign 时.   例:  #box {background-color:# ...

  3. Cloudera 安装

    参考网址: http://tcxiang.iteye.com/blog/2087597 http://archive.cloudera.com/cdh5/ http://archive.clouder ...

  4. CodeForces 869B

    Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...

  5. NYOJ 814 又见拦截导弹 (模拟)

    题目链接 描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:它的第一发炮弹能够到达任意的高度,但是以 ...

  6. 24、CSS定位

    CSS定位方法 driver.find_element_by_css_selector() 1.CSS定位常用策略(方式) 1.id选择器 说明:根据元素id属性来选择 格式:#id 如:#userA ...

  7. CMDB概述(二)

    运维自动化路线: cmdb的开发需要包含三部分功能: ·采集硬件数据  ·API ·页面管理 执行流程:服务器的客户端采集硬件数据,然后将硬件信息发送到API,API负责将获取到的数据保存到数据库中, ...

  8. hdu 5319 Painter(杭电多校赛第三场)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5319 Painter Time Limit: 2000/1000 MS (Java/Others)   ...

  9. app 测试基础

    1. 安装和启动 (1) OTA安装测试 ·         app必须能够通过ota安装到测试设备上 ·         如果app安装完后没有icon,那么必须能够通过其他的方法来启动这个app ...

  10. python并发编程之multiprocessing进程(二)

    python的multiprocessing模块是用来创建多进程的,下面对multiprocessing总结一下使用记录. 系列文章 python并发编程之threading线程(一) python并 ...