lijyya的方法
蓝书上的方法,是lijyya给的,整一个坐标系方法
虽然她很厉害
但是也很可爱
光速逃离~~~)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rint register int
#define rll register ll
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define p1 first
//#define p2 second
const ll inf = 1e8;
// const ll maxn =
#define fors(i, a, b) for (ll i = (a); i <= (b); ++i)
#define _fors(i, a, b) for (ll i = (a); i >= (b); --i)
#define mp(a, b) make_pair(a, b)
#define mem(A, b) memset(A, b, sizeof(A))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define endl '\n'
#define fab(a) a>0?a:-a
const double PI = 3.141592653589793;
struct Point {
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {
}
};
typedef Point Vector;
Vector operator+(Vector A, Vector B) {
return Vector(A.x + B.x, A.y + B.y);
}
Vector operator-(Point A, Point B) {
return Vector(A.x - B.x, A.y - B.y);
}
Vector operator*(double p, Vector A) {
return Vector(A.x * p, A.y * p);
}
Vector operator*(Vector A, double p) {
return Vector(A.x * p, A.y * p);
}
Vector operator/(Vector A, double p) {
return Vector(A.x / p, A.y / p);
}
const double eps = 1e-6;
int dcmp(double x) {
if (fabs(x) < eps)
return 0;
else
return x < 0 ? -1 : 1;
}
bool operator==(const Point& a, const Point& b) {
return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;
}
bool operator<(const Point& a, const Point& b) {
if (dcmp(a.x - b.x) == 0)
return a.y < b.y;
return a.x < b.x;
}
double Dot(Vector A, Vector B) {
return A.x * B.x + A.y * B.y;
}
double Length(Vector A) {
return sqrt(Dot(A, A));
}
double Angle(Vector A, Vector B) {
return acos(Dot(A, B) / Length(A) / Length(B));
}
double Cross(Vector A, Vector B) { // 叉积
return A.x * B.y - A.y * B.x;
}
double Area2(Point A, Point B, Point C) {
return Cross(B - A, C - A);
}
Vector Rotate(Vector A, double rad) { // 逆时针
return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
}
Vector Normal(Vector A) { // 逆时针 90 的单位向量
double L = Length(A);
return Vector(-A.y / L, A.x / L);
}
Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) { // 线线交点 PQ & vw
Vector u = P - Q;
return P + Cross(w, u) * v / Cross(v, w);
}
double DistanceToLine(Point P, Point A, Point B) {
Vector v1 = B - A, v2 = P - A;
return fabs(Cross(v1, v2) / Length(v1));
}
double DistanceToSegment(Point P, Point A, Point B) {
if (A == B)
return Length(P - A);
Vector v1 = B - A, v2 = P - A, v3 = P - B;
if (dcmp(Dot(v1, v2)) < 0)
return Length(v2);
else if (dcmp(Dot(v1, v3) > 0))
return Length(v3);
else
return fabs(Cross(v1, v2)) / Length(v1);
}
Point GetLineProjection(Point P, Point A, Point B) { // P 在 AB 上的投影点
Vector v = B - A;
return A + v * (Dot(v, P - A) / Dot(v, v));
}
bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) { // 线段是否有交点 a1a2 & b1b2
double c1 = Cross(a2 - a1, b1 - a1);
double c2 = Cross(a2 - a1, b2 - a1);
double c3 = Cross(b2 - b1, a1 - b1);
double c4 = Cross(b2 - b1, a2 - b1);
return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;
}
bool OnSegment(Point p, Point a1, Point a2) { // P 是否在线段 a1a2 上
return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;
}
typedef vector<Point> Polygon; // 多边形
int isPointInPolygon(const Point& p, const Polygon& poly) { // 点与多边形位置关系
int n = poly.size();
int wn = 0;
for (int i = 0; i < n; i++) {
const Point& p1 = poly[i];
const Point& p2 = poly[(i + 1) % n];
if (p1 == p || p2 == p || OnSegment(p, p1, p2))
return -1; // 在边界上
int k = dcmp(Cross(p2 - p1, p - p1));
int d1 = dcmp(p1.y - p.y);
int d2 = dcmp(p2.y - p.y);
if (k > 0 && d1 <= 0 && d2 > 0)
wn++;
if (k < 0 && d2 <= 0 && d1 > 0)
wn--;
}
if (wn != 0)
return 1; // 内部
return 0; // 外部
}
bool isDiagonal(const Polygon& poly, int a, int b) { // 下标为 a b 的点组成的线是否是对角线
int n = poly.size();
for (int i = 0; i < n; i++)
if (i != a && i != b && OnSegment(poly[i], poly[a], poly[b]))
return false; // 中间不能有其他点
for (int i = 0; i < n; i++)
if (SegmentProperIntersection(poly[i], poly[(i + 1) % n], poly[a], poly[b]))
return false; // 不能和多边形的边规范相交
Point midp = (poly[a] + poly[b]) * 0.5;
return (isPointInPolygon(midp, poly) == 1); // 整条线段在多边形内
}
double ConvexPolygonArea(Point* p, int n) { // 凸多边形的面积
double area = 0;
for (int i = 1; i < n - 1; i++)
area += Cross(p[i] - p[0], p[i + 1] - p[0]);
return area / 2;
}
double PolygonArea(Point* p, int n) { // 多边形的面积
double area = 0;
for (int i = 1; i < n - 1; i++)
area += Cross(p[i] - p[0], p[i + 1] - p[0]);
return area / 2;
}
struct Circle {
Point c;
double r;
Circle() {
}
Circle(Point c, double r) : c(c), r(r) {
}
Point point(double a) { // 圆边界上的点,与圆心连线是圆心右边水平线逆时针旋转
return Point(c.x + cos(a) * r, c.y + sin(a) * r);
}
};
struct Line { // p 代表起始点,v 代表方向和长度 (计算几何都是点法式)
Point P;
Vector v;
double ang; // 极角,从 x 正半轴逆时针旋转到向量 v 所需要的角
Line() {
}
Line(Point P, Vector v) : P(P), v(v) {
ang = atan2(v.y, v.x); // atan2(y, x) == atan(y / x)
}
bool operator<(const Line& L) const {
return dcmp(ang - L.ang) < 0;
}
Point point(double t) {
return P + v * t;
}
};
// 设交点 P = A + t(B - A)
int GetLineCircleIntersection(Line L, Circle C, double& t1, double& t2, vector<Point>& sol) {
double a = L.v.x, b = L.P.x - C.c.x, c = L.v.y, d = L.P.y - C.c.y;
double e = a * a + c * c, f = 2 * (a * b + c * d), g = b * b + d * d - C.r * C.r;
double delta = f * f - 4 * e * g;
if (dcmp(delta) < 0)
return 0; // 相离
if (dcmp(delta) == 0) {
t1 = t2 = -f / (2 * e);
sol.pb(L.point(t1));
return 1; // 相切
}
t1 = (-f - sqrt(delta)) / (2 * e);
sol.pb(L.point(t1));
t2 = (-f + sqrt(delta)) / (2 * e);
sol.pb(L.point(t2));
return 2; // 相交
}
double angle(Vector v) { // 向量极角
return atan2(v.y, v.x);
}
int GetCircleCircleIntersection(Circle C1, Circle C2, vector<Point>& sol) {
double d = Length(C1.c - C2.c);
if (dcmp(d) == 0) {
if (dcmp(C1.r - C2.r) == 0)
return -1;
return 0;
}
if (dcmp(C1.r + C2.r - d) < 0)
return 0;
if (dcmp(fabs(C1.r - C2.r) - d) > 0)
return 0;
double a = angle(C2.c - C1.c);
double da = acos((C1.r * C1.r + d * d - C2.r * C2.r) / (2 * C1.r * d));
Point p1 = C1.point(a - da), p2 = C1.point(a + da);
sol.pb(p1);
if (p1 == p2)
return 1;
sol.pb(p2);
return 2;
}
int GetTangents(Point p, Circle C, Vector* v) { // 切线,点圆
Vector u = C.c - p;
double dist = Length(u);
if (dist < C.r)
return 0;
else if (dcmp(dist - C.r) == 0) {
v[0] = Rotate(u, PI / 2);
return 1;
} else {
double ang = asin(C.r / dist);
v[0] = Rotate(u, -ang);
v[1] = Rotate(u, +ang);
return 2;
}
}
int GetTangents(Circle A, Circle B, Point* a, Point* b) { // 切线,圆圆
int cnt = 0;
if (A.r < B.r) {
swap(A, B);
swap(a, b);
}
double d2 = (A.c.x - B.c.x) * (A.c.x - B.c.x) + (A.c.y - B.c.y) * (A.c.y - B.c.y);
double rdiff = A.r - B.r;
double rsum = A.r + B.r;
if (d2 < rdiff * rdiff)
return 0;
double base = atan2(B.c.y - A.c.y, B.c.x - A.c.x);
if (dcmp(d2) == 0 && dcmp(A.r - B.r) == 0)
return -1;
if (dcmp(d2 - rdiff * rdiff) == 0) {
a[cnt] = A.point(base);
b[cnt] = B.point(base);
cnt++;
return 1;
}
double ang = acos((A.r - B.r) / sqrt(d2));
a[cnt] = A.point(base + ang);
b[cnt] = B.point(base + ang);
cnt++;
a[cnt] = A.point(base - ang);
b[cnt] = B.point(base - ang);
cnt++;
if (dcmp(d2 - rsum * rsum) == 0) {
a[cnt] = A.point(base);
b[cnt] = B.point(PI + base);
cnt++;
} else if (d2 > rsum * rsum) {
ang = acos((A.r + B.r) / sqrt(d2));
a[cnt] = A.point(base + ang);
b[cnt] = B.point(base + ang);
cnt++;
a[cnt] = A.point(PI + base - ang);
b[cnt] = B.point(PI + base - ang);
cnt++;
}
return cnt;
}
Vector GetAngleBisectorDefinition(Point p, Point lef, Point rig) { // 角平分线
int res = dcmp(Cross(rig - p, lef - p));
if (res == 0)
return lef - p;
if (res < 0)
swap(lef, rig);
return Rotate(rig - p, 0.5 * Angle(rig - p, lef - p));
}
Circle CircumscribedCircle(Point p1, Point p2, Point p3) { // 外接圆
double Bx = p2.x - p1.x, By = p2.y - p1.y;
double Cx = p3.x - p1.x, Cy = p3.y - p1.y;
double D = 2 * (Bx * Cy - By - Cx);
double cx = (Cy * (Bx * Bx + By * By) - By * (Cx * Cx + Cy * Cy)) / D + p1.x;
double cy = (Bx * (Cx * Cx + Cy * Cy) - Cx * (Bx * Bx + By * By)) / D + p1.y;
Point p = Point(cx, cy);
return Circle(p, Length(p1 - p));
}
Circle InscribedCircle(Point p1, Point p2, Point p3) { // 内接圆
double a = Length(p2 - p3);
double b = Length(p3 - p1);
double c = Length(p1 - p2);
Point p = (p1 * a + p2 * b + p3 * c) / (a + b + c);
return Circle(p, DistanceToSegment(p, p1, p2));
}
int IsPointInPolygon(Point p, Polygon poly) { // 点是否在多边形内
int wn = 0;
int n = poly.size();
fors(i, 0, n - 1) {
if (OnSegment(p, poly[i], poly[(i + 1) % n]) || p == poly[i] || p == poly[(i + 1) % n])
return -1; // 在边上
int k = dcmp(Cross(poly[(i + 1) % n] - poly[i], p - poly[i]));
int d1 = dcmp(poly[i].y - p.y);
int d2 = dcmp(poly[(i + 1) % n].y - p.y);
if (k > 0 && d1 <= 0 && d2 > 0)
wn++;
if (k < 0 && d2 <= 0 && d1 > 0)
wn--;
}
if (wn)
return 1; // 在里面
return 0; // 在外面
}
int ConvexHull(Point* p, int n,
Point* ch) { // 凸包,返回顶点数,输出点数组 ch (如果不想凸包边上有点,把两个 <= 改成 <)
sort(p, p + n);
int m = 0;
fors(i, 0, n - 1) {
while (m > 1 && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0)
m--;
ch[m++] = p[i];
}
int k = m;
_fors(i, n - 2, 0) {
while (m > k && dcmp(Cross(ch[m - 1] - ch[m - 2], p[i] - ch[m - 2])) <= 0)
m--;
ch[m++] = p[i];
}
if (n > 1)
m--;
return m;
}
double GetDiameter(Point* ch, int n) { // 多边形直径
if (n == 1)
return 0.0;
if (n == 2)
return Length(ch[0] - ch[1]);
int j = 2;
double ret = 0.0;
fors(i, 0, n - 1) {
while (Cross(ch[i] - ch[(i + 1) % n], ch[(i + 1) % n] - ch[j]) <
Cross(ch[i] - ch[(i + 1) % n], ch[(i + 1) % n] - ch[(j + 1) % n]))
j = (j + 1) % n;
ret = max(Length(ch[i] - ch[j]), Length(ch[(i + 1) % n] - ch[j]));
}
return ret;
}
bool OnLeft(Line L, Point p) { // 点在线的左边
return dcmp(Cross(L.v, p - L.P)) > 0;
}
Point GetIntersection(Line a, Line b) { // 两线交点
Vector u = a.P - b.P;
double t = Cross(b.v, u) / Cross(a.v, b.v);
return a.P + a.v * t;
}
Polygon CutPolygon(Polygon poly, Point A,
Point B) { // 用有向直线 A->B 切割多边形,返回左侧,若退化,可能返回单点或线段
Polygon newpoly;
int n = poly.size();
fors(i, 0, n - 1) {
Point C = poly[i];
Point D = poly[(i + 1) % n];
if (dcmp(Cross(B - A, C - A)) >= 0)
newpoly.push_back(C);
if (dcmp(Cross(B - A, C - D)) != 0) {
Point ip = GetLineIntersection(A, B - A, C, D - C);
if (OnSegment(ip, C, D))
newpoly.push_back(ip);
}
}
return newpoly;
}
int HalfplaneIntersection(
Line* L, int n,
Point* poly) { // 半平面交
// (若干个半平面的相交部分,每个半平面用一条有向线段表示,他的箭头方向的左边代表半平面)
sort(L, L + n);
int first, last; // 双端队列首尾元素下标
Point* p = new Point[n]; // p[i] 是 q[i] q[i + 1] 交点
Line* q = new Line[n]; // deque
q[first = last = 0] = L[0]; // deque 初始化就一半平面 L[0]
fors(i, 1, n - 1) {
while (first < last && !OnLeft(L[i], p[last - 1]))
last--;
while (first < last && !OnLeft(L[i], p[first]))
first++;
q[++last] = L[i];
if (fabs(Cross(q[last].v, q[last - 1].v)) < eps) {
last--;
if (OnLeft(q[last], L[i].P))
q[last] = L[i];
}
if (first < last)
p[last - 1] = GetIntersection(q[last - 1], q[last]);
}
while (first < last && !OnLeft(q[first], p[last - 1]))
last--;
if (last - first <= 1)
return 0;
p[last] = GetIntersection(q[last], q[first]); // 首尾两个半平面的交点
int m = 0;
fors(i, first, last) poly[m++] = p[i];
return m;
}
Point p[110], ch[110];
int n;
double a;
// double eps = 1e-6;
double s[110];
int main() {
scanf("%lf %d", &a, &n);
for (int i = 0; i < n; ++i) {
scanf("%lf %lf", &ch[i].x, &ch[i].y);
}
//n = ConvexHull(ch, n, p);
memcpy(p,ch,sizeof(p));
// sort(p, p + n);
double S = ConvexPolygonArea(p, n);
double ss = 0;
for (int i = 0; i < n; ++i) {
Point pp[3];
pp[0] = p[i];
pp[1] = p[(i + 1) % n];
pp[2] = p[(i + 2) % n];
ss += ConvexPolygonArea(pp, 3);
}
ss=fab(ss);
S=fab(S);
// printf("%lf\n", ss);
double ct = S - a * S;
// double l = eps, r = 1 - eps;
// while (l < r) {
// double mid = (l + r) / 2;
// if (mid * mid * ss > ct) {
// r = mid - eps;
// } else {
// l = mid + eps;
// }
// }
// printf("%.6lf\n", 1 / r);
// printf("%lf %lf %lf\n", S, ss, ct);
double l = 2.0, r = 1000.0;
while (l < r) {
double mid = (l + r) / 2;
if (mid * mid * ct <= ss) {
l = mid + eps;
} else {
r = mid - eps;
}
}
printf("%.7lf\n", l);
}