bzoj 1185: [HNOI2007]最小矩形覆盖 (旋转卡壳)

1185: [HNOI2007]最小矩形覆盖

Time Limit: 10 Sec   Memory Limit: 162 MBSec   Special Judge
Submit: 1406   Solved: 633
[ Submit][ Status][ Discuss]

Description

bzoj 1185: [HNOI2007]最小矩形覆盖 (旋转卡壳)_第1张图片 

bzoj 1185: [HNOI2007]最小矩形覆盖 (旋转卡壳)_第2张图片

Input

Output

Sample Input

Sample Output

HINT

Source

计算几何 vfleaking提供Spj

[ Submit][ Status][ Discuss]

题解:与hdu 5251 类似,不过要求正方形的顶点。

#include
#include
#include
#include
#include
#define eps 1e-8
#define N 100003
using namespace std;
int n,m;
struct vector {
	double x,y;
	vector (double X=0,double Y=0){
		x=X,y=Y;
	}
}a[N],ch[N],line[5];
double pi=acos(-1.0),ans;
typedef vector point;
struct data{
	double ans;
	point a,b,c,d;
}tmp;
vector operator -(vector a,vector b){
	return vector (a.x-b.x,a.y-b.y);
}
vector operator +(vector a,vector b){
	return vector (a.x+b.x,a.y+b.y);
}
vector operator *(vector a,double t){
	return vector (a.x*t,a.y*t);
}
vector operator /(vector a,double t){
	return vector (a.x/t,a.y/t);
}
bool operator <(vector a,vector b){
	return a.x1&&cross(ch[m-1]-ch[m-2],a[i]-ch[m-2])<=0) m--;
		ch[m++]=a[i];
	}
	int k=m;
	for (int i=n-1;i>=1;i--){
		while (m>k&&cross(ch[m-1]-ch[m-2],a[i]-ch[m-2])<=0) m--;
		ch[m++]=a[i];
	}
	m--;
}
double len(vector a){
	return sqrt(a.x*a.x+a.y*a.y);
}
double distl(point p,point a,point b){
	vector v=b-a; vector u=p-a;
	return fabs(cross(v,u))/len(v);
}
vector rotate(vector a,double rad)
{
	return vector(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
point glt(point a,point b,point c,point d)
{
	//cout<distl(ch[k],ch[0],ch[1])) k=t;
	for (int t=2;t=dot(ch[1]-ch[0],ch[i]-ch[1])) i=t;
	for (int t=2;t=dot(ch[0]-ch[1],ch[j]-ch[0])) j=t;
	double h=distl(ch[k],ch[0],ch[1]);
	double l=len(ch[0]-ch[1])+fabs(dot(ch[1]-ch[0],ch[i]-ch[1]))/len(ch[0]-ch[1])+fabs(dot(ch[0]-ch[1],ch[j]-ch[0]))/len(ch[0]-ch[1]);
	ans=h*l; tmp.ans=ans;
	update(ch[0],ch[1],ch[k],ch[i],ch[j]);
	ch[m]=ch[0];
    for (int t=1;t



你可能感兴趣的:(计算几何)