标签:bzoj shoi2014 计算几何 随机增量法 最小圆覆盖
题目大意:给出平面上的一些点,现在让你用一个长轴与x轴成一定角度的,长轴:短轴已知的椭圆来覆盖所有的坐标,求最小的短轴长度。
思路:很明显,这个椭圆的形状和放置状态已经给出了,但是没有办法求最小拖圆覆盖啊。采用坐标变换,将椭圆变成圆。首先我们先让长轴与x轴平行,将平面上的所有点都旋转这个角度。之后只需要让所有点的x坐标除以长轴:短轴就可以了。剩下的就是最小圆覆盖了。
注:坐标旋转公式:
x‘ = x * cos(a) - y * sin(a)
y‘ = x * sin(a) + y * cos(a)
CODE:
#define _CRT_SECURE_NO_WARNINGS #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define MAX 50010 #define PI (acos(-1.0)) using namespace std; struct Point{ double x,y; Point(double _,double __):x(_),y(__) {} Point() {} 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 *(double a)const { return Point(x * a,y * a); } void Read() { scanf("%lf%lf",&x,&y); } }point[MAX]; inline double Cross(const Point &p1,const Point &p2) { return p1.x * p2.y - p1.y * p2.x; } inline double Calc(const Point &p1,const Point &p2) { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); } inline Point Mid(const Point &p1,const Point &p2) { return Point((p1.x + p2.x) / 2,(p1.y + p2.y) / 2); } inline Point Change(const Point &v) { return Point(-v.y,v.x); } inline void Rotate(Point &p,double alpha) { p = Point(p.x * cos(alpha) - p.y * sin(alpha),p.x * sin(alpha) + p.y * cos(alpha)); } struct Circle{ Point o; double r; Circle(const Point &_,double __):o(_),r(__) {} bool InCircle(const Point &p) { return Calc(o,p) <= r; } }; struct Line{ Point p,v; Line(const Point &_,const Point &__):p(_),v(__) {} }; inline Point GetIntersection(const Line &l1,const Line &l2) { Point u = l1.p - l2.p; double t = Cross(l2.v,u) / Cross(l1.v,l2.v); return l1.p + l1.v * t; } int points; double a,p; int main() { cin >> points; for(int i = 1; i <= points; ++i) point[i].Read(); cin >> a >> p; random_shuffle(point + 1,point + points + 1); for(int i = 1; i <= points; ++i) { Rotate(point[i],(1 - a / 360) * 2 * PI); point[i].x /= p; } Circle now(point[1],.0); for(int i = 2; i <= points; ++i) if(!now.InCircle(point[i])) { now = Circle(point[i],.0); for(int j = 1; j < i; ++j) if(!now.InCircle(point[j])) { now = Circle(Mid(point[i],point[j]),Calc(point[i],point[j]) / 2); for(int k = 1; k < j; ++k) if(!now.InCircle(point[k])) { Line l1(Mid(point[i],point[j]),Change(point[j] - point[i])); Line l2(Mid(point[j],point[k]),Change(point[k] - point[j])); Point intersection = GetIntersection(l1,l2); now = Circle(intersection,Calc(intersection,point[i])); } } } cout << fixed << setprecision(3) << now.r << endl; return 0; }
BZOJ 3564 SHOI 2014 信号增幅仪 坐标变换+最小圆覆盖
标签:bzoj shoi2014 计算几何 随机增量法 最小圆覆盖
原文地址:http://blog.csdn.net/jiangyuze831/article/details/43951355