bzoj3564

洛谷P4288

可以旋转一下坐标轴使得x轴与长轴方向对齐,然后将所有的横坐标变为自身除以放大倍数,然后就做一个最小圆覆盖

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<ctime>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
namespace X
{
const double pi=acos(-);
const double eps=1e-;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y){}
};
typedef Point Vec;
Vec operator+(const Vec& a,const Vec& b)
{
return Vec(a.x+b.x,a.y+b.y);
}
Vec operator-(const Vec& a,const Vec& b)
{
return Vec(a.x-b.x,a.y-b.y);
}
Vec operator*(double a,const Vec& b)
{
return Vec(a*b.x,a*b.y);
}
Vec operator*(const Vec& a,double b)
{
return Vec(b*a.x,b*a.y);
}
Vec operator/(const Vec& a,double b)
{
return Vec(a.x/b,a.y/b);
}
int dcmp(double x)
//正为1,负为-1,0为0
{
if(fabs(x)<eps) return ;
return x<?-:;
}
bool operator==(const Vec& a,const Vec& b)
//判向量相等
{
return dcmp(a.x-b.x)==&&dcmp(a.y-b.y)==;
}
double dot(const Vec& a,const Vec& b)
//点积
{
return a.x*b.x+a.y*b.y;
}
double cross(const Vec& a,const Vec& b)
//叉积
{
return a.x*b.y-a.y*b.x;
}
double len(const Vec& x)
//向量长度
{
return sqrt(dot(x,x));
}
double angle(const Vec& a,const Vec& b)
//夹角,0~180°
{
return acos(dot(a,b)/len(a)/len(b));
}
double angle1(const Vec& a,const Vec& b)
//夹角,带方向,a到b逆时针为正,顺时针为负,共线为0
{
return acos(dot(a,b)/len(a)/len(b))*(dcmp(cross(a,b)));
}
Vec rotate(const Vec& a,double rad)
//旋转,正为逆时针,负为顺时针
{
return Vec(a.x*cos(rad)-a.y*sin(rad),a.x*sin(rad)+a.y*cos(rad));
}
Vec normal(const Vec& x)
//单位法线,左转90°后除以自身长度
{
double l=len(x);
return Vec(-x.y/l,x.x/l);
}
Vec normal1(const Vec& x)
//法线,不归一化
{
return Vec(-x.y,x.x);
}
Point lineline(const Point& p,const Vec& v,const Point& q,const Vec& w)
//直线交点,GetLineIntersection
{
return p+v*cross(w,p-q)/cross(v,w);
}
double ptline(const Point& p,const Point& a,const Point& b)
//point_to_line,点到直线距离,DistanceToLine
{
Vec v1=b-a,v2=p-a;
return fabs(cross(v1,v2)/len(v1));
}
double ptseg(const Point& p,const Point& a,const Point& b)
//point_to_segment,点到线段距离,DistanceToSegment
{
if(a==b) return len(p-a);
//Vec v1=b-a,v2=a-p,v3=p-b;
Vec v1=b-a,v2=p-a,v3=p-b;
if(dcmp(dot(v1,v2))<) return len(v2);
else if(dcmp(dot(v1,v3))>) return len(v3);
else return fabs(cross(v1,v2)/len(v1));
}
double area2(const Point& a,const Point& b,const Point& c)
//叉积对应平行四边形的面积
{
return cross(b-a,c-a);
}
double thrarea(const Point& a,const Point& b,const Point& c)
//三角形面积,绝对值
{
return fabs(cross(b-a,c-a)/);
}
bool ifpar(const Vec& a,const Vec& b)
//ifParallel
//是否共线/平行
{
return dcmp(cross(a,b))==;
}
Point pointline(const Point& p,const Point& a,const Vec& v)
//点在直线上投影,GetLineProjection
{
return a+v*(dot(p-a,v)/dot(v,v));
}
double sqr(double x){return x*x;}
double dis2(const Point &x,const Point &y)
{
return sqr(x.x-y.x)+sqr(x.y-y.y);
}
double len2(const Vec &x){return dot(x,x);}
};
using namespace X;
Point p[];
int n;
Point a;
double r2;
double A,B;
void make(const Point &x,const Point &y)
{
Vec t=(y-x)/;
a=x+t;
r2=len2(t);
}
void make(const Point &x,const Point &y,const Point &z)
{
Vec t1=(y-x)/,t2=(z-y)/;
Point x1=x+t1,y1=y+t2;
t1=normal1(t1);t2=normal1(t2);
a=lineline(x1,t1,y1,t2);
r2=dis2(a,x);
}
bool ok(const Point &x)
{
return dcmp(dis2(x,a)-r2)<=;
}
int main()
{
int i,j,k;
srand(time());
scanf("%d",&n);
for(i=;i<=n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
scanf("%lf%lf",&A,&B);A=A/*pi;
for(i=;i<=n;i++)
p[i]=rotate(p[i],-A);
for(i=;i<=n;i++)
p[i].x/=B;
random_shuffle(p+,p+n+);
a=p[];r2=;
for(i=;i<=n;i++)
if(!ok(p[i]))
{
a=p[i];r2=;
for(j=;j<i;j++)
if(!ok(p[j]))
{
make(p[i],p[j]);
for(k=;k<j;k++)
if(!ok(p[k]))
{
make(p[i],p[j],p[k]);
}
}
}
//uprintf("%.2f %.2f ",a.x,a.y);
printf("%.3f\n",sqrt(r2));
return ;
}
05-11 20:15