本文主要是介绍uva 12307 - Smallest Enclosing Rectangle(旋转卡壳),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:uva 12307 - Smallest Enclosing Rectangle
两组踵对点围成长方形,枚举出所有可行长方形维护最小值。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <complex>
#include <algorithm>using namespace std;
typedef pair<int,int> pii;
const double pi = 4 * atan(1);
const double eps = 1e-10;inline int dcmp (double x) { if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1; }
inline double getDistance (double x, double y) { return sqrt(x * x + y * y); }
inline double torad(double deg) { return deg / 180 * pi; }struct Point {double x, y;Point (double x = 0, double y = 0): x(x), y(y) {}void read () { scanf("%lf%lf", &x, &y); }void write () { printf("%lf %lf", x, y); }bool operator == (const Point& u) const { return dcmp(x - u.x) == 0 && dcmp(y - u.y) == 0; }bool operator != (const Point& u) const { return !(*this == u); }bool operator < (const Point& u) const { return x < u.x || (x == u.x && y < u.y); }bool operator > (const Point& u) const { return u < *this; }bool operator <= (const Point& u) const { return *this < u || *this == u; }bool operator >= (const Point& u) const { return *this > u || *this == u; }Point operator + (const Point& u) { return Point(x + u.x, y + u.y); }Point operator - (const Point& u) { return Point(x - u.x, y - u.y); }Point operator * (const double u) { return Point(x * u, y * u); }Point operator / (const double u) { return Point(x / u, y / u); }double operator * (const Point& u) { return x*u.y - y*u.x; }
};
typedef Point Vector;
typedef vector<Point> Polygon;struct Line {double a, b, c;Line (double a = 0, double b = 0, double c = 0): a(a), b(b), c(c) {}
};struct DirLine {Point p;Vector v;double ang;DirLine () {}DirLine (Point p, Vector v): p(p), v(v) { ang = atan2(v.y, v.x); }bool operator < (const DirLine& u) const { return ang < u.ang; }
};struct Circle {Point o;double r;Circle () {}Circle (Point o, double r = 0): o(o), r(r) {}void read () { o.read(), scanf("%lf", &r); }Point point(double rad) { return Point(o.x + cos(rad)*r, o.y + sin(rad)*r); }double getArea (double rad) { return rad * r * r / 2; }
};namespace Punctual {double getDistance (Point a, Point b) { double x=a.x-b.x, y=a.y-b.y; return sqrt(x*x + y*y); }
};namespace Vectorial {/* 点积: 两向量长度的乘积再乘上它们夹角的余弦, 夹角大于90度时点积为负 */double getDot (Vector a, Vector b) { return a.x * b.x + a.y * b.y; }/* 叉积: 叉积等于两向量组成的三角形有向面积的两倍, cross(v, w) = -cross(w, v) */double getCross (Vector a, Vector b) { return a.x * b.y - a.y * b.x; }double getLength (Vector a) { return sqrt(getDot(a, a
这篇关于uva 12307 - Smallest Enclosing Rectangle(旋转卡壳)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!