text
stringlengths
49
983k
#include <bits/stdc++.h> const double pi = 3.1415926535897932384626433832795; bool test(long long x1, long long y1, long long x2, long long y2, long long x3, long long y3) { long long vx1 = x2 - x1; long long vy1 = y2 - y1; long long vx2 = x3 - x1; long long vy2 = y3 - y1; return ((vx1 * vx2 + vy1 * vy2) > 0); } long long vc(long long x1, long long y1, long long x2, long long y2) { return (x1 * y2 - x2 * y1); } using namespace std; int main() { int n, i; long long x0, y0, x, y, xp, yp, xf, yf; double rmx = 0, rmn = 1000000000; cin >> n >> x0 >> y0; cin >> xf >> yf; xp = xf; yp = yf; for (i = 0; i < n - 1; i++) { cin >> x >> y; rmx = max(rmx, hypot(x - x0, y - y0)); rmn = min(rmn, hypot(x - x0, y - y0)); if (test(xp, yp, x, y, x0, y0) && test(x, y, xp, yp, x0, y0)) rmn = min(rmn, abs(vc(x - x0, y - y0, xp - x0, yp - y0)) / (hypot(x - xp, y - yp))); xp = x; yp = y; } x = xf; y = yf; rmx = max(rmx, hypot(x - x0, y - y0)); rmn = min(rmn, hypot(x - x0, y - y0)); if (test(xp, yp, x, y, x0, y0) && test(x, y, xp, yp, x0, y0)) rmn = min(rmn, abs(vc(x - x0, y - y0, xp - x0, yp - y0)) / (hypot(x - xp, y - yp))); cout.precision(30); cout << pi * (rmx * rmx - rmn * rmn); return 0; }
#include <bits/stdc++.h> using namespace std; struct st { double x, y; } ar[100010]; struct point { double x, y; point() {} point(double xx, double yy) { x = xx, y = yy; } } P[100010]; point centre; struct vec { double x, y; vec() {} vec(point xx, point yy) { x = yy.x - xx.x, y = yy.y - xx.y; } }; double dotproduct(vec a, vec b) { return (a.x * b.x + a.y * b.y); } double crossproduct(vec a, vec b) { return (a.x * b.y - a.y * b.x); } double norm_sq(vec a) { return (a.x * a.x + a.y * a.y); } double angle(point A, point B, point C) { vec BA(B, A), BC(B, C); return acos(dotproduct(BA, BC) / sqrt(norm_sq(BA) * norm_sq(BC))); } double triangleArea(point a, point b, point c) { double area = a.x * b.y + b.x * c.y + c.x * a.y; area -= (b.x * a.y + c.x * b.y + a.x * c.y); return area; } double area(int n) { double A = 0; P[n].x = P[0].x; P[n].y = P[0].y; for (int i = 0; i < n; i++) { A += (P[i].x * P[i + 1].y - P[i + 1].x * P[i].y); } return A < 0 ? -A : A; } double Distance(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } double pointSegmentDistance(point C, point A, point B) { vec BA(B, A); vec AB(A, B); vec AC(A, C); vec BC(B, C); double dot = dotproduct(BA, AC); if (dot >= 0) return Distance(A, C); dot = dotproduct(AB, BC); if (dot >= 0) return Distance(B, C); return fabs(crossproduct(AB, AC) / sqrt(norm_sq(AB))); } int main() { int n; cin >> n >> centre.x >> centre.y; double mini = 1e8, mx = 0; pair<int, int> value; double low = 1e8; for (int i = 0; i < n; i++) { cin >> P[i].x >> P[i].y; mx = max(mx, Distance(centre, P[i])); if (i) { mini = min(mini, pointSegmentDistance(centre, P[i], P[i - 1])); } } mini = min(mini, pointSegmentDistance(centre, P[n - 1], P[0])); double ans = acos(-1.0) * (mx * mx - mini * mini); printf("%.20lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 111111; long long x[N], y[N]; int n; long long cx, cy; double det(double x1, double y1, double x2, double y2) { return x1 * y2 - x2 * y1; } double dot(double x1, double y1, double x2, double y2) { return x1 * x2 + y1 * y2; } int main() { ios::sync_with_stdio(false); cout.precision(24); cin >> n >> cx >> cy; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } double minDist = 1e13, maxDist = 0; for (int i = 1; i <= n; i++) { double ax = x[i], ay = y[i]; double bx = x[i % n + 1], by = y[i % n + 1]; double abx = bx - ax, aby = by - ay; double acx = cx - ax, acy = cy - ay; double bcx = cx - bx, bcy = cy - by; double ds = dot(acx, acy, acx, acy); maxDist = max(maxDist, ds); minDist = min(minDist, ds); double det1 = det(acx, acy, aby, -abx); double det2 = det(bcx, bcy, aby, -abx); if ((det1 < 0) != (det2 < 0)) { ds = pow(det(abx, aby, acx, acy), 2) / (abx * abx + aby * aby); minDist = min(minDist, ds); } } double ans = 3.14159265358979323 * (maxDist - minDist); cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> double pi = 3.1415926; double INF = 1e100; double EPS = 1e-12; int p[100005], q[100005]; struct PT { double x, y; PT() {} PT(double x, double y) : x(x), y(y) {} PT(const PT &p) : x(p.x), y(p.y) {} PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); } PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); } PT operator*(double c) const { return PT(x * c, y * c); } PT operator/(double c) const { return PT(x / c, y / c); } }; double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; } double dist2(PT p, PT q) { return dot(p - q, p - q); } double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; } PT ProjectPointSegment(PT a, PT b, PT c) { double r = dot(b - a, b - a); if (fabs(r) < EPS) return a; r = dot(c - a, b - a) / r; if (r < 0) return a; if (r > 1) return b; return a + (b - a) * r; } double DistancePointSegment(PT a, PT b, PT c) { return sqrt(dist2(c, ProjectPointSegment(a, b, c))); } int main() { int i, n, x, y; double j = -1, k = 0, m = 0; scanf("%d %d %d", &n, &x, &y); PT pnt(x, y); for (i = 0; i < n; i++) { scanf("%d %d", &p[i], &q[i]); PT pp(p[i], q[i]); m = dist2(pnt, pp); if (j == -1) j = m; if (k < m) k = m; if (j > m) j = m; } for (i = 0; i < n; i++) { int jj = (i + 1) % n; PT a(p[i], q[i]), b(p[jj], q[jj]); double res = dist2(pnt, ProjectPointSegment(a, b, pnt)); if (j > res) j = res; } printf("%.10f", (k - j) * pi); return 0; }
#include <bits/stdc++.h> using namespace std; double FindDistanceToSegment(double x1, double y1, double x2, double y2, double pointX, double pointY) { double diffX = x2 - x1; float diffY = y2 - y1; if ((diffX == 0) && (diffY == 0)) { diffX = pointX - x1; diffY = pointY - y1; return sqrt(diffX * diffX + diffY * diffY); } float t = ((pointX - x1) * diffX + (pointY - y1) * diffY) / (diffX * diffX + diffY * diffY); if (t < 0) { diffX = pointX - x1; diffY = pointY - y1; } else if (t > 1) { diffX = pointX - x2; diffY = pointY - y2; } else { diffX = pointX - (x1 + t * diffX); diffY = pointY - (y1 + t * diffY); } return sqrt(diffX * diffX + diffY * diffY); } int main() { int n; double x_P, y_P; scanf("%d%lf%lf", &n, &x_P, &y_P); double x1, y1; scanf("%lf%lf", &x1, &y1); double distance_min = sqrt((x1 - x_P) * (x1 - x_P) + (y1 - y_P) * (y1 - y_P)); double distance_max = sqrt((x1 - x_P) * (x1 - x_P) + (y1 - y_P) * (y1 - y_P)); double PI = acos(-1); double x_L = x1, y_L = y1; double xx, yy; for (int i(1); i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); distance_min = min(distance_min, FindDistanceToSegment(x, y, x_L, y_L, x_P, y_P)); if (i == n - 1) distance_min = min(distance_min, FindDistanceToSegment(x, y, x1, y1, x_P, y_P)); double distance = sqrt((x - x_P) * (x - x_P) + (y - y_P) * (y - y_P)); distance_min = min(distance_min, distance); distance_max = max(distance_max, distance); x_L = x, y_L = y; } printf("%0.20lf\n", PI * (distance_max * distance_max - distance_min * distance_min)); return 0; }
#include <bits/stdc++.h> using namespace std; const long double PIE = 3.14159265358979323846; class Point { public: long double x, y; Point(long double x, long double y) : x(x), y(y) {} }; long double distance(const Point& A, const Point& B) { return ((A.x - B.x) * (A.x - B.x)) + ((A.y - B.y) * (A.y - B.y)); } long double cross(const Point& A, const Point& B) { return A.x * B.y - A.y * B.x; } long double dot(const Point& A, const Point& B) { return A.x * B.x + A.y * B.y; } Point vec(const Point& A, const Point& B) { return Point(A.x - B.x, A.y - B.y); } long double distance(const Point& P, const Point& A, const Point& B) { if (dot(vec(A, B), vec(B, P)) > 0) return distance(P, B); if (dot(vec(B, A), vec(A, P)) > 0) return distance(P, A); return ((cross(vec(A, B), vec(A, P))) * (cross(vec(A, B), vec(A, P)))) / distance(A, B); } void solve() { int n; cin >> n; int cx, cy; cin >> cx >> cy; Point C(cx, cy); vector<Point> P; for (int i = 1; i <= n; i++) { long double x, y; cin >> x >> y; P.emplace_back(x, y); } long double farthest = 0; for (Point p : P) { farthest = max(farthest, distance(C, p)); } long double closest = farthest; for (Point p : P) { closest = min(closest, distance(C, p)); } for (int i = 0; i < n; i++) { Point p1 = P[i]; Point p2 = P[(i + 1) % n]; closest = min(closest, distance(C, p1, p2)); } cout << fixed << setprecision(20) << PIE * (farthest - closest) << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; for (int i = 1; i <= t; i++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int N, x, y; complex<long double> s, p[100000]; long double dist(int i, int j, long double k) { complex<long double> pp = p[i] + (p[j] - p[i]) * k; return abs(pp - s); } int main(void) { cin >> N >> x >> y; s = complex<long double>(x, y); long double ma = 0, mi = 10000000000000000LL; for (int i = 0; i < (int)(N); ++i) cin >> x >> y, p[i] = complex<long double>(x, y); for (int i = 0; i < (int)(N); ++i) ma = max(ma, abs(s - p[i])); for (int i = 0; i < (int)(N); ++i) { int l = i, r = (i + 1) % N; long double lb = 0, ub = 1; for (int roop = 0; roop < (int)(100); ++roop) { long double lmid = (ub - lb) / 3.0 + lb, rmid = (ub - lb) / 3.0 * 2.0 + lb; long double lval = dist(l, r, lmid), rval = dist(l, r, rmid); if (lval < rval) ub = rmid; else lb = lmid; } mi = min(mi, dist(l, r, ub)); } cout << setprecision(10) << fixed << 3.14159265358979 * (ma * ma - mi * mi) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; inline double min(double x, double y) { return x < y ? x : y; } inline double max(double x, double y) { return x > y ? x : y; } inline double _abs(double x) { return x < 0 ? -x : x; } const int maxn = 100000 + 10; const double pi = acos(-1); int n; double mn, mx; struct Node { double x, y; } p, s[maxn]; inline double dis(Node a, Node b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } inline double mndis(Node a, Node b) { double d1 = dis(a, b), d2 = dis(a, p), d3 = dis(b, p); if (d2 >= d1 + d3) return d3; if (d3 >= d1 + d2) return d2; double d = fabs((a.x - p.x) * (b.y - p.y) - (a.y - p.y) * (b.x - p.x)); return d * d / d1; } int main() { scanf("%d", &n); scanf("%lf%lf", &p.x, &p.y); mx = 0; mn = 1e20; for (int i = 1; i <= n; ++i) { scanf("%lf%lf", &s[i].x, &s[i].y); mx = max(mx, dis(s[i], p)); } mn = mndis(s[1], s[n]); for (int i = 1; i < n; ++i) mn = min(mn, mndis(s[i], s[i + 1])); printf("%.18lf", pi * (mx - mn)); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } double d[100005]; double x[100005]; double y[100005]; double f(double x1, double y1, double x2, double y2, double pointX, double pointY) { double diffX = x2 - x1; float diffY = y2 - y1; if ((diffX == 0) && (diffY == 0)) { diffX = pointX - x1; diffY = pointY - y1; return sqrt(diffX * diffX + diffY * diffY); } float t = ((pointX - x1) * diffX + (pointY - y1) * diffY) / (diffX * diffX + diffY * diffY); if (t < 0) { diffX = pointX - x1; diffY = pointY - y1; } else if (t > 1) { diffX = pointX - x2; diffY = pointY - y2; } else { diffX = pointX - (x1 + t * diffX); diffY = pointY - (y1 + t * diffY); } return sqrt(diffX * diffX + diffY * diffY); } int main() { int n; double cx, cy; double mx = 0.0, mn = DBL_MAX; cin >> n >> cx >> cy; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; double dx = x[i] - cx; double dy = y[i] - cy; double dz = dx * dx + dy * dy; d[i] = sqrt(dz); if (i > 0) { double pd = f(x[i], y[i], x[i - 1], y[i - 1], cx, cy); mn = min(mn, pd); if (i == n - 1) mn = min(mn, f(x[0], y[0], x[n - 1], y[n - 1], cx, cy)); } mx = max(mx, d[i]); } double a1 = 3.14159265358979323846 * mx * mx; double a2 = 3.14159265358979323846 * mn * mn; double ans = a1 - a2; printf("%.18lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} void input() { scanf("%lf%lf", &x, &y); } }; Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); } Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); } Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); } bool operator<(const Point &a, const Point &b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } int dcmp(double x) { if (fabs(x) < 1e-8) return 0; else return x < 0 ? -1 : 1; } bool operator==(const Point &a, const Point &b) { return !dcmp(a.x - b.x) && !dcmp(a.y - b.y); } double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } double Length(Point A) { return sqrt(Dot(A, A)); } double Angle(Point A, Point B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } double Area2(Point A, Point B, Point C) { return Cross(B - A, C - A); } Point Rotate(Point A, double rad) { return Point(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad)); } Point GetLineIntersection(Point P, Point v, Point Q, Point w) { Point u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v * t; } double DistanceToLine(Point P, Point A, Point B) { Point 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); Point 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 p0, p[maxn]; int main() { int n; scanf("%d", &n); p0.input(); double maxdis = -1, mindis = 1e9 + 7; for (int i = 0; i < n; i++) { p[i].input(); maxdis = max(maxdis, Length(p0 - p[i])); } p[n] = p[0]; for (int i = 0; i < n; i++) { mindis = min(mindis, DistanceToSegment(p0, p[i], p[i + 1])); } printf("%.8lf\n", acos(-1) * (maxdis * maxdis - mindis * mindis)); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 50; const double eps = 1e-10; const int max_index = 62; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double PI = 3.14159265358979323; inline int read() { char c = getchar(); while (!isdigit(c)) c = getchar(); int x = 0; while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return x; } struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} }; Point operator+(const Point& A, const Point& B) { return Point(A.x + B.x, A.y + B.y); } Point operator-(const Point& A, const Point& B) { return Point(A.x - B.x, A.y - B.y); } Point operator*(const Point& A, double p) { return Point(A.x * p, A.y * p); } Point operator/(const Point& A, double p) { return Point(A.x / p, A.y / p); } bool operator<(const Point& a, const Point& b) { return a.x < b.x || (a.x == b.x && a.y < b.y); } int dcmp(double x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; } bool operator==(const Point& a, const Point& b) { return !dcmp(a.x - b.x) && !dcmp(a.y - b.y); } double Dot(const Point& A, const Point& B) { return A.x * B.x + A.y * B.y; } double Cross(const Point& A, const Point& B) { return A.x * B.y - A.y * B.x; } double Length(const Point& A) { return sqrt(Dot(A, A)); } double Angle(const Point& A, const Point& B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Area2(const Point& A, const Point& B, const Point& C) { return Cross(B - A, C - A); } Point Rotate(const Point& A, double rad) { return Point(A.x + cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad)); } Point Normal(const Point& A) { double L = Length(A); return Point(-A.y / L, A.x / L); } Point GetLineIntersection(const Point& P, const Point& v, const Point& Q, const Point& w) { Point u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v * t; } double DistanceToLine(const Point& P, const Point& A, const Point& B) { Point v1 = B - A, v2 = P - A; return fabs(Cross(v1, v2) / Length(v1)); } double DistanceToSegment(const Point& P, const Point& A, const Point& B) { if (A == B) return Length(P - A); Point v1 = B - A, v2 = P - A, v3 = P - B; if (dcmp(Dot(v1, v2)) < 0) return Length(v2); if (dcmp(Dot(v1, v3)) > 0) return Length(v3); return fabs(Cross(v1, v2) / Length(v1)); } Point GetLineProjection(const Point& P, const Point& A, const Point& B) { Point v = B - A; return A + v * (Dot(v, P - A) / Dot(v, v)); } bool SegmentProperIntersection(const Point& a1, const Point& a2, const Point& b1, const Point& b2) { double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1), c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1); return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0; } bool OnSegment(const Point& p, const Point& a1, const Point& a2) { return !dcmp(Cross(a1 - p, a2 - p)) && dcmp(Dot(a1 - p, a2 - p)) < 0; } 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; } Point ReadPoint() { Point res; scanf("%lf%lf", &res.x, &res.y); return res; } int n; Point P, p[maxn]; int main() { scanf("%d", &n); P = ReadPoint(); double l = 10000000, r = -1; for (int i = 1; i <= n; i++) { p[i] = ReadPoint(); r = max(r, Length(p[i] - P)); } p[n + 1] = p[1]; for (int i = 1; i <= n; i++) { l = min(l, DistanceToSegment(P, p[i], p[i + 1])); } printf("%.10f\n", PI * (r * r - l * l)); return 0; }
#include <bits/stdc++.h> using namespace std; char _; const int maxN = 200 * 1000 + 5; const int mod = 1000 * 1000 * 1000 + 7; const int base = 701; const int SQ = 600; const int maxL = 20; const long double PI = 3.14159265359; pair<int, int> a[maxN]; pair<long double, long double> operator-(pair<long double, long double> p, pair<long double, long double> q) { return {p.first - q.first, p.second - q.second}; } long double dot(pair<long double, long double> p, pair<long double, long double> q) { return p.first * q.first + p.second * q.second; } long double dis(pair<long double, long double> p) { return sqrt(p.first * p.first + p.second * p.second); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int n, x, y; cin >> n >> x >> y; long long mx = 0; for (int i = 0; i < n; i++) { int tx, ty; cin >> tx >> ty; a[i].first = tx; a[i].second = ty; tx -= x; ty -= y; long long tmp = (1LL) * tx * tx + (1LL) * ty * ty; mx = max(mx, tmp); } long double mn = (1LL) * mod * mod; for (int i = 0; i < n; i++) { pair<int, int> A = a[i], B = a[(i + 1) % n], C = {x, y}; long double res = dot(B - A, C - A) / dot(B - A, B - A); pair<long double, long double> H = (B - A); H.first *= res; H.second *= res; H.first += A.first; H.second += A.second; if (0 <= res && res <= 1) mn = min(mn, dis(H - C)); else mn = min(mn, min(dis(B - C), dis(A - C))); } mn *= mn; cout << fixed << setprecision(20) << (mx - mn) * acos(-1) << endl; return 0; }
#include <bits/stdc++.h> class point { friend std::istream& operator>>(std::istream&, point&); public: point(); double distance(const point& other) const; double dot(const point& other) const; point& operator-=(const point& other); int x() const { return x_; } int y() const { return y_; } private: int x_, y_; }; std::ostream& operator<<(std::ostream&, const point&); point operator-(const point&, const point&); class segment { public: segment(const point& a, const point& b); double distance(const point& p) const; private: point a_, b_; }; using namespace std; double circle_area(double radius); const double pi = 2 * acos(0); int main() { int vertices; point center; cout.precision(8); cout.setf(ios::fixed); while (cin >> vertices >> center) { double largest_radius = 0; double smallest_radius = 1e100; point first, last; for (int i = 0; i < vertices; i++) { point p; cin >> p; if (i != 0) smallest_radius = min(smallest_radius, segment(p, last).distance(center)); else first = p; largest_radius = max(largest_radius, p.distance(center)); last = p; } smallest_radius = min(smallest_radius, segment(first, last).distance(center)); cout << circle_area(largest_radius) - circle_area(smallest_radius) << '\n'; } } double circle_area(double radius) { return pi * radius * radius; } point::point() : x_(0), y_(0) {} std::istream& operator>>(std::istream& in, point& p) { return in >> p.x_ >> p.y_; } std::ostream& operator<<(std::ostream& out, const point& p) { return out << '(' << p.x() << ',' << p.y() << ')'; } point operator-(const point& a, const point& b) { point p = a; return p -= b; } point& point::operator-=(const point& other) { x_ -= other.x_; y_ -= other.y_; return *this; } double square(double d) { return d * d; } double point::distance(const point& other) const { return sqrt(square(x() - other.x()) + square(y() - other.y())); } double point::dot(const point& other) const { return static_cast<double>(x()) * other.x() + static_cast<double>(y()) * other.y(); } segment::segment(const point& a, const point& b) : a_(a), b_(b) {} double segment::distance(const point& p) const { double t = (p - a_).dot(b_ - a_) / square(a_.distance(b_)); if (t > 0 && t < 1) { double mx = a_.x() + t * (b_ - a_).x(); double my = a_.y() + t * (b_ - a_).y(); return sqrt(square(mx - p.x()) + square(my - p.y())); } return min(b_.distance(p), a_.distance(p)); }
#include <bits/stdc++.h> using namespace std; bool eq(double a, double b) { if (fabs(a - b) <= 1e-6) return true; else return false; } bool neq(double a, double b) { if (fabs(a - b) > 1e-6) return true; else return false; } bool lt(double a, double b) { if (a + 1e-6 < b) return true; else return false; } bool le(double a, double b) { if (a < b + 1e-6) return true; else return false; } bool gt(double a, double b) { if (a > b + 1e-6) return true; else return false; } bool ge(double a, double b) { if (a + 1e-6 > b) return true; else return false; } struct line { double a, b, c; }; double dot(pair<double, double>& u, pair<double, double>& w) { return u.first * w.first + u.second * w.second; } line l2p(pair<double, double>& a, pair<double, double>& b) { line l; l.a = b.second - a.second; l.b = a.first - b.first; l.c = -(b.second - a.second) * a.first - (a.first - b.first) * a.second; return l; } line lperpend(line l, pair<double, double> a) { line m; m.a = -l.b; m.b = l.a; m.c = l.b * a.first - l.a * a.second; return m; } pair<double, double> pfoot(line l, pair<double, double> a) { double z = (l.a * a.first + l.b * a.second + l.c) / (l.a * l.a + l.b * l.b); pair<double, double> f; f.first = a.first - l.a * z; f.second = a.second - l.b * z; return f; } bool inbetween(pair<double, double> c, pair<double, double> a, pair<double, double> b) { double dotp = (b.first - a.first) * (c.first - a.first) + (b.second - a.second) * (c.second - a.second); if (lt(dotp, 0)) return false; double dist = (b.first - a.first) * (b.first - a.first) + (b.second - a.second) * (b.second - a.second); return dotp <= dist; } double d(pair<double, double> a, pair<double, double> b) { double d1 = b.first - a.first; double d2 = b.second - a.second; return sqrt(d1 * d1 + d2 * d2); } double dlp(pair<double, double> a, pair<double, double> c, pair<double, double> b) { line l = l2p(a, c); pair<double, double> z = pfoot(l, b); if (inbetween(z, a, c)) return d(b, z); return -1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; double dist, r1 = 2e6, r2 = -1; cin >> n; pair<double, double> g; cin >> g.first >> g.second; vector<pair<double, double> > v(n); for (int i = 0; i < n; i++) { cin >> v[i].first >> v[i].second; dist = d(v[i], g); if (lt(dist, r1)) r1 = dist; if (gt(dist, r2)) r2 = dist; } double k; for (int i = 0; i < n; i++) { k = dlp(v[i], v[(i + 1) % n], g); if (k != -1 && le(k, r1)) r1 = k; } cout << setprecision(10) << 3.141592653589793 * (r2 * r2 - r1 * r1) << "\n"; }
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point() { x = 0.0; y = 0.0; } point(double xx, double yy) { x = xx; y = yy; } point operator+(const point& p) const { return point(x + p.x, y + p.y); } point operator-(const point& p) const { return point(x - p.x, y - p.y); } point operator*(double k) const { return point(k * x, k * y); } double operator^(const point& p) { return x * p.y - p.x * y; } double sqlen() { return x * x + y * y; } double len() { return sqrt(sqlen()); } }; double dot(const point& a, const point& b) { return (a.x * b.x + a.y * b.y); } double sqdist(const point& a, const point& b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } double dist(const point& a, const point& b) { return sqrt(sqdist(a, b)); } vector<point> v; double psdist(point& p, point& a, point& b) { double t = dot(p - a, b - a) / sqdist(a, b); if (t < 0.0) return sqdist(a, p); if (t > 1.0) return sqdist(b, p); point q = a + (b - a) * t; return sqdist(q, p); } int main() { int n; point p; double maxdist = -1.0, mindist = 1e18; scanf("%d %lf %lf", &n, &p.x, &p.y); for (int i = 0; i < n; i++) { point cur; scanf("%lf %lf", &cur.x, &cur.y); v.push_back(cur); maxdist = max(maxdist, sqdist(p, cur)); } for (int i = 0; i < n; i++) { int ii = (n + i - 1) % n; mindist = min(mindist, psdist(p, v[i], v[ii])); } double ans = M_PI * maxdist - M_PI * mindist; printf("%.18lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long double dist(pair<long long, long long> p1, pair<long long, long long> p2) { return sqrt((p2.first - p1.first) * (p2.first - p1.first) + (p2.second - p1.second) * (p2.second - p1.second)); } long double getans(complex<long double> a, complex<long double> b) { long double s1 = (conj(a) * b).imag(); s1 = abs(s1) / 2.0; return 2 * s1 / abs(b); } long double scalmul(long double x1, long double y1, long double x2, long double y2) { return x1 * x2 + y1 * y2; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(7); cout.setf(ios::fixed); int n; cin >> n; pair<long long, long long> p; cin >> p.first >> p.second; long double minR = 4e18; long double maxR = 0; vector<pair<long long, long long> > a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; long double cur = dist(p, a[i]); if (cur > maxR) { maxR = cur; } if (cur < minR) { minR = cur; } } for (int i = 0; i < n; i++) { pair<long long, long long> p1 = a[i]; pair<long long, long long> p2 = a[(i + 1) % n]; long double x1 = p1.first; long double y1 = p1.second; long double x2 = p2.first; long double y2 = p2.second; long double x3 = p.first; long double y3 = p.second; if (scalmul(x3 - x1, y3 - y1, x2 - x1, y2 - y1) > 0 && scalmul(x3 - x2, y3 - y2, x1 - x2, y1 - y2) > 0) { complex<long double> a(x3 - x1, y3 - y1); complex<long double> b(x2 - x1, y2 - y1); long double cur = getans(a, b); if (cur < minR) { minR = cur; } } else { complex<long double> a1(x3 - x1, y3 - y1); complex<long double> a2(x3 - x2, y3 - y2); long double cur = min(abs(a1), abs(a2)); if (cur < minR) { minR = cur; } } } long double pi = acos(-1.0); cout << pi * (maxR * maxR - minR * minR); return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = INT_LEAST64_MAX; const unsigned long long ullinf = 0x7fffffff; double eps = 1e-10; int mod = 1e9 + 7; const int N = 3e6 + 10; const double pi = acos(-1.0); struct pt { double x, y; pt(double a, double b) : x(a), y(b) {} }; double dist(pt a, pt b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } struct ln { pt s, e; double a, b, c; ln(pt a, pt b) : s(a), e(b) {} void pton() { a = e.y - s.y; b = s.x - e.x; c = e.x * s.y - e.y * s.x; } double dis(pt t) { pton(); double res = (a * t.x + b * t.y + c) / sqrt(a * a + b * b); double xp = (b * b * t.x - a * b * t.y - a * c) / (a * a + b * b); double yp = (-a * b * t.x + a * a * t.y - b * c) / (a * a + b * b); double xb = max(s.x, e.x); double yb = max(s.y, e.y); double xs = s.x + e.x - xb; double ys = s.y + e.y - yb; if (xp > xb + eps || xp < xs - eps || yp > yb + eps || yp < ys - eps) res = min(dist(t, s), dist(t, e)); return fabs(res); } }; int main() { int n; scanf("%d", &n); double x, y; cin >> x >> y; double e, f; double mir = inf, mxr = 0; double a, b; cin >> a >> b; e = a, f = b; double d1 = (a - x) * (a - x) + (b - y) * (b - y); mir = min(d1, mir); mxr = max(d1, mxr); for (int i = 1; i <= n - 1; i++) { double c, d; cin >> c >> d; double ds = pow(ln(pt(a, b), pt(c, d)).dis(pt(x, y)), 2); mir = min(ds, mir); a = c, b = d; double d1 = (a - x) * (a - x) + (b - y) * (b - y); mir = min(d1, mir); mxr = max(d1, mxr); } double ds = pow(ln(pt(a, b), pt(e, f)).dis(pt(x, y)), 2); mir = min(ds, mir); mxr = max(mxr, ds); cout << fixed << setprecision(18) << pi * (mxr - mir); }
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-9; const int INF = (int)1e9; const int N = (int)1e5 + 5; const long long M = (int)1e9 + 7; const long double Pi = 3.14159265358979; bool equal(long double a, long double b) { return abs(a - b) < EPS; } long double dist(long double x1, long double y1, long double x2, long double y2) { return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); } long double dist2(long double x1, long double y1, long double x2, long double y2, long double x3, long double y3) { long double sk1, sk2; sk1 = (x3 - x2) * (x1 - x2) + (y3 - y2) * (y1 - y2); sk2 = (x2 - x3) * (x1 - x3) + (y2 - y3) * (y1 - y3); if ((equal(sk1, 0) || sk1 > 0) && (equal(sk2, 0) || sk2 > 0)) return abs(((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / dist(x3, y3, x2, y2)); else return min(dist(x1, y1, x2, y2), dist(x1, y1, x3, y3)); } int x[N], y[N]; int main() { int n, x1, y1; long double R = -1, r = INF; cin >> n >> x1 >> y1; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; x[n] = x[0], y[n] = y[0]; for (int i = 0; i < n; i++) { R = max(R, dist(x1, y1, x[i], y[i])); r = min(r, dist2(x1, y1, x[i], y[i], x[i + 1], y[i + 1])); } cout.precision(15); cout << fixed << Pi * R * R - Pi * r * r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; double x, y; double a[100011], b[100011]; double dis(double a, double b) { return sqrt(a * a + b * b); } double delt(double x, double y, double a, double b) { return x * b - a * y; } int main() { cin >> n >> x >> y; for (int i = 1; i <= n; i++) { scanf("%lf%lf", &a[i], &b[i]); } a[n + 1] = a[1]; b[n + 1] = b[1]; double mi, ma; ma = 0; for (int i = 1; i <= n; i++) { if (ma < dis(a[i] - x, b[i] - y)) { ma = dis(a[i] - x, b[i] - y); } } mi = ma; for (int i = 1; i <= n; i++) { double qx, qy; qx = a[i] - a[i + 1]; qy = b[i] - b[i + 1]; swap(qx, qy); qx = -qx; mi = min(mi, dis(a[i] - x, b[i] - y)); if (delt(qx, qy, a[i] - x, b[i] - y) * delt(qx, qy, a[i + 1] - x, b[i + 1] - y) <= 0) { static double sum; sum = delt(a[i] - x, b[i] - y, a[i + 1] - x, b[i + 1] - y); if (sum < 0) sum = -sum; sum = sum / dis(a[i] - a[i + 1], b[i] - b[i + 1]); mi = min(mi, sum); } } double PI = 3.1415926535898; printf("%.16lf", PI * (ma * ma - mi * mi)); }
#include <bits/stdc++.h> using namespace std; const int Maxn = 100000 + 10; const double PI = M_PI; const double eps = 1e-8; int dcmp(double a) { if (fabs(a) < eps) return 0; if (a > 0) return 1; return -1; } struct Point { double x, y; Point operator+(const Point &A) { return (Point){A.x + x, A.y + y}; } Point operator-(const Point &A) { return (Point){x - A.x, y - A.y}; } } P, Poly[Maxn]; int n; struct Line { Point P; Point V; } Line[Maxn]; double CalDJ(Point A, Point B) { return A.x * B.x + A.y * B.y; } double CalCJ(Point A, Point B) { return A.x * B.y - A.y * B.x; } double CalLen(Point A) { return sqrt(CalDJ(A, A)); } double CalDIS(Point P, Point A, Point B) { Point v1 = B - A, v2 = P - A, v3 = P - B; if (dcmp(CalDJ(v1, v2)) < 0) return CalLen(v2); if (dcmp(CalDJ(v1, v3)) > 0) return CalLen(v3); return fabs(CalCJ(v1, v2) / CalLen(v1)); } double Getdis(Point Q) { long long dx = Q.x - P.x, dy = Q.y - P.y; long long ret = dx * dx + dy * dy; return ret; } double Max, Min; void solve() { scanf("%d", &n); scanf("%lf%lf", &P.x, &P.y); for (int i = 1; i <= n; i++) scanf("%lf%lf", &Poly[i].x, &Poly[i].y); Min = Getdis(Poly[1]); for (int i = 1; i <= n; i++) { double di = Getdis(Poly[i]); if (di > Max) Max = di; if (di < Min) Min = di; } Poly[n + 1] = Poly[1]; for (int i = 1; i <= n; i++) { double dis = CalDIS(P, Poly[i], Poly[i + 1]); dis = dis * dis; if (dis < Min) Min = dis; } double ans = PI * (Max - Min); printf("%lf\n", ans); } int main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; void FastIO() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cout.precision(15); } long long modpow(long long a, long long p, long long mod) { long long ret = 1; while (p) { if (p & 1) ret = (ret * a) % mod; a = (a * a) % mod; p /= 2; } return ret % mod; } long long power(long long a, long long p) { long long ret = 1; while (p) { if (p & 1) ret = (ret * a); a = (a * a); p /= 2; } return ret; } double eps = 1e-7; inline long double dist(double x1, double y1, double x2, double y2) { long double ret = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); return ret; } double x, y; double pdis(double x1, double y1, double x2, double y2) { double A = x - x1; double B = y - y1; double C = x2 - x1; double D = y2 - y1; double dot = A * C + B * D; double len_sq = C * C + D * D; double param = -1; if (len_sq != 0) param = dot / len_sq; double xx, yy; if (param < 0) { xx = x1; yy = y1; } else if (param > 1) { xx = x2; yy = y2; } else { xx = x1 + param * C; yy = y1 + param * D; } double dx = x - xx; double dy = y - yy; return dx * dx + dy * dy; } vector<pair<double, double> > vec; int main() { FastIO(); int n; cin >> n; cin >> x >> y; double mx = -1, mn = LLONG_MAX; for (int i = 0; i < n; i++) { double a, b; int p, q; cin >> p >> q; a = p; b = q; vec.push_back(make_pair(a, b)); double d = dist(x, y, a, b); mx = ((mx < d) ? d : mx); mn = ((mn < d) ? mn : d); } for (int i = 0; i < n; i++) mn = ((mn < pdis(vec[i].first, vec[i].second, vec[(i + 1) % n].first, vec[(i + 1) % n].second)) ? mn : pdis(vec[i].first, vec[i].second, vec[(i + 1) % n].first, vec[(i + 1) % n].second)); double ans = mx - mn; ans = M_PI * ans; cout << fixed << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; double FindDistanceToSegment(double x1, double y1, double x2, double y2, double pointX, double pointY) { double diffX = x2 - x1; float diffY = y2 - y1; if ((diffX == 0) && (diffY == 0)) { diffX = pointX - x1; diffY = pointY - y1; return sqrt(diffX * diffX + diffY * diffY); } float t = ((pointX - x1) * diffX + (pointY - y1) * diffY) / (diffX * diffX + diffY * diffY); if (t < 0) { diffX = pointX - x1; diffY = pointY - y1; } else if (t > 1) { diffX = pointX - x2; diffY = pointY - y2; } else { diffX = pointX - (x1 + t * diffX); diffY = pointY - (y1 + t * diffY); } return sqrt(diffX * diffX + diffY * diffY); } double cal(double x, double y, double x1, double y1) { return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1)); } void tp() {} int main() { for (int z = 0; z < 5; z++) ; for (int z = 0; z < 5; z++) ; for (int z = 0; z < 5; z++) ; for (int z = 0; z < 5; z++) ; tp(); tp(); tp(); cout << fixed << setprecision(12); int n; double distance, pie = acos(-1), M = 0, m = 1000000000000007; pair<double, double> p[100005]; double lineX1, lineY1, lineX2, lineY2, pointX, pointY; cin >> n >> pointX >> pointY; for (int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second; for (int i = 2; i <= n; i++) { lineX1 = p[i].first; lineY1 = p[i].second; lineX2 = p[i - 1].first; lineY2 = p[i - 1].second; distance = FindDistanceToSegment(lineX1, lineY1, lineX2, lineY2, pointX, pointY); if (distance > M) M = distance; if (distance < m) m = distance; distance = cal(pointX, pointY, lineX1, lineY1); if (distance > M) M = distance; if (distance < m) m = distance; } lineX1 = p[1].first; lineY1 = p[1].second; lineX2 = p[n].first; lineY2 = p[n].second; distance = FindDistanceToSegment(lineX1, lineY1, lineX2, lineY2, pointX, pointY); if (distance > M) M = distance; if (distance < m) m = distance; distance = cal(pointX, pointY, lineX1, lineY1); if (distance > M) M = distance; if (distance < m) m = distance; cout << pie * (M * M - m * m) << endl; for (int z = 0; z < 5; z++) ; for (int z = 0; z < 5; z++) ; for (int z = 0; z < 5; z++) ; for (int z = 0; z < 5; z++) ; for (int z = 0; z < 5; z++) ; for (int z = 0; z < 5; z++) ; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 3; long long x, y; long long rx, ry; int n; pair<long long, long long> P[MAXN]; const long double PI = acos((-1.0L)); long double dist(const pair<long long, long long> &p) { return sqrt( ((long double)p.first * p.first + (long double)p.second * p.second)); } long double dist2Line(const pair<long long, long long> &p1, const pair<long long, long long> &p2) { long double s = 0; long double d1 = dist(p1); long double d2 = dist(p2); long double d3 = sqrt(((long double)(p1.first - p2.first) * (p1.first - p2.first) + (long double)(p1.second - p2.second) * (p1.second - p2.second))); if (d2 * d2 >= d1 * d1 + d3 * d3) return d1; if (d1 * d1 >= d2 * d2 + d3 * d3) return d2; long double p = (d1 + d2 + d3) / 2; s = sqrt(p * (p - d1) * (p - d2) * (p - d3)); return min(s * 2 / d3, min(d1, d2)); } void solve() { cin >> n >> rx >> ry; long double mi = 1e9, ma = 0; long double d; for (int i = 0; i < n; ++i) { scanf("%I64d %I64d", &P[i].first, &P[i].second); P[i].first -= rx; P[i].second -= ry; ma = max(ma, dist(P[i])); } rx = ry = 0; P[n] = P[0]; for (int i = 0; i < n; ++i) { mi = min(mi, dist2Line(P[i], P[i + 1])); } long double res = (ma * ma - mi * mi) * PI; cout << res; } int main() { cout << fixed << setprecision(15); solve(); return 0; }
#include <bits/stdc++.h> const double pi = acos(-1.0); const double eps = 1e-8; struct point { double x, y; } x[100005], p; double Max(double x, double y) { return x > y ? x : y; } double Min(double x, double y) { return x < y ? x : y; } double dis(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } point len(point a, point b, point p) { point tp = a; if (a.y == b.y && a.x != b.x) { double l = Min(a.x, b.x), r = Max(a.x, b.x); if (p.x >= l && p.x <= r) { tp.x = p.x; tp.y = a.y; return tp; } else if (p.x < l) { tp.x = l; tp.y = a.y; return tp; } else { tp.x = r; tp.y = a.y; return tp; } } else if (a.x == b.x && a.y != b.y) { double l = Min(a.y, b.y), r = Max(a.y, b.y); if (p.y >= l && p.y <= r) { tp.y = p.y; tp.x = a.x; return tp; } else if (p.y < l) { tp.y = l; tp.y = a.y; return tp; } else { tp.y = r; tp.x = a.x; return tp; } } else if (a.y != b.y && a.x != b.x) { double k = (b.y - a.y) / (b.x - a.x); double x = (k * k * a.x + k * (p.y - a.y) + p.x) / (k * k + 1), y = k * (x - a.x) + a.y; double l = Min(a.x, b.x), r = Max(a.x, b.x); if (x >= l && x <= r) { point tp; tp.x = x; tp.y = y; return tp; } else if (x < l) { if (a.x > b.x) { return b; } else { return a; } } else { if (a.x > b.x) { return a; } else { return b; } } } } int main() { int n; while (~scanf("%d%lf%lf", &n, &p.x, &p.y)) { double dismax = 0; for (int i = 0; i < n; ++i) { scanf("%lf%lf", &x[i].x, &x[i].y); dismax = Max(dis(p, x[i]), dismax); } double sum, dismin = 1e18; for (int i = 0; i < n; ++i) { point tp; tp = len(x[i], x[(i + 1) % n], p); double tplen = dis(p, tp); dismin = Min(dismin, tplen); } sum = pi * (dismax * dismax - dismin * dismin); printf("%.12f\n", sum); } return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 7; const int N = 1e5 + 5; const double PI = acos(-1); struct point { double x, y; }; double dist(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } double scal(double x, double y, double x1, double y1, double x3, double y3) { pair<double, double> p = make_pair(x1 - x, y1 - y), h = make_pair(x3 - x, y3 - y); return p.first * h.first + p.second * h.second; } double g(point a, point b, point c) { double sc = scal(b.x, b.y, c.x, c.y, a.x, a.y); if (sc <= 0) { return dist(a, b); } sc = scal(c.x, c.y, b.x, b.y, a.x, a.y); if (sc <= 0) { return dist(a, c); } double x, y, z; y = -1; if (b.x == c.x) { return abs(a.x - b.x); } x = (b.y - c.y) / (b.x - c.x); z = b.y - x * b.x; return abs((x * a.x + y * a.y + z) / sqrt(x * x + y * y)); } int n; point points[N]; int main() { cin >> n; cin >> points[0].x >> points[0].y; double mn = 1e18, mx = 0; for (int i = 1; i <= n; i++) { cin >> points[i].x >> points[i].y; mx = max(mx, dist(points[0], points[i])); if (i > 1) { mn = min(mn, g(points[0], points[i - 1], points[i])); } } mn = min(mn, g(points[0], points[1], points[n])); cout << fixed << setprecision(10) << (mx * mx * PI) - (mn * mn * PI) << endl; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 10000005; int n; pair<long double, long double> st; pair<long double, long double> p; long double Max = -1; long double Min = 100000000000000000; long double Min1 = 100000000000000000; vector<pair<long double, long double>> v; long double calc() { long double ret = pow(abs(p.first - st.first), 2) + pow(abs(p.second - st.second), 2); return ret; } void cal() { n = v.size(); for (int i = 0; i < v.size(); i++) { long double a = sqrt(pow((v[i % n].first - v[(i + 1) % n].first), 2) + pow((v[i % n].second - v[(i + 1) % n].second), 2)); long double b = sqrt(pow((v[i % n].first - st.first), 2) + pow((v[i % n].second - st.second), 2)); long double c = sqrt(pow((st.first - v[(i + 1) % n].first), 2) + pow((st.second - v[(i + 1) % n].second), 2)); long double C = (pow(a, 2) + pow(b, 2) - pow(c, 2)) / (2 * a * b); long double B = (pow(c, 2) + pow(a, 2) - pow(b, 2)) / (2 * a * c); if (C >= 0 && B >= 0) { long double cur = b * sqrt((long double)(1 - pow(C, 2))); Min1 = min(Min1, cur * cur); } } return; } int main() { ios::sync_with_stdio(0), cin.tie(0); cin >> n >> st.first >> st.second; while (n--) { cin >> p.first >> p.second; v.push_back(make_pair(p.first, p.second)); Max = max(Max, calc()); Min = min(Min, calc()); } cal(); long double first = 3.141592653589793116; Min1 = min(Min1, Min); long double ans = first * (Max - Min1); cout << fixed << setprecision(18) << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const double pi = acos(-1); int n, x, y; double mx, mn = 1e18; struct node { double x, y; } a[maxn]; double cross(node a, node b) { return a.x * b.y - b.x * a.y; } double dis(double x1, double y1, double x2, double y2) { double a = y1 - y2, b = x2 - x1, c = +x1 * y2 - y1 * x2; if (a * a + b * b == 0) return 1e18; double d = pi * (a * x + b * y + c) * (a * x + b * y + c) / (a * a + b * b); node u = (node){x1 - x, y1 - y}, v = (node){x2 - x, y2 - y}, t = (node){y1 - y2, x2 - x1}; if (cross(u, t) * cross(v, t) < 0) return d; return 1e18; } int main() { scanf("%d%d%d", &n, &x, &y); for (int i = 1; i <= n; i++) { scanf("%lf%lf", &a[i].x, &a[i].y); double d = (x - a[i].x) * (x - a[i].x) + (y - a[i].y) * (y - a[i].y); mx = max(mx, d); mn = min(mn, d); } mx *= pi, mn *= pi; for (int i = 2; i <= n; i++) mn = min(mn, dis(a[i].x, a[i].y, a[i - 1].x, a[i - 1].y)); mn = min(mn, dis(a[1].x, a[1].y, a[n].x, a[n].y)); printf("%.15lf", mx - mn); return 0; }
#include <bits/stdc++.h> using namespace std; double PI = 3.141592653589793238462643383279; double len(double x0, double y0, double x1, double y1, double x2, double y2) { double a = y2 - y1, b = x1 - x2, c = x1 * (y1 - y2) + y1 * (x2 - x1); return abs((a * x0 + b * y0 + c)) / (sqrt(a * a + b * b)); } int check(double x0, double y0, double x1, double y1, double x2, double y2) { double a = y2 - y1, b = x1 - x2, c = x1 * (y1 - y2) + y1 * (x2 - x1); double xnew = (x0 * b * b - b * y0 * a - a * c) / (a * a + b * b); double ynew = (y0 * a * a - b * x0 * a - b * c) / (a * a + b * b); if ((xnew >= min(x1, x2)) && (xnew <= max(x1, x2)) && (ynew >= min(y1, y2)) && (ynew <= max(y1, y2))) return 1; else return 0; } int main() { int n; double x0, y0, x1, y1, x2, y2, xstart, ystart; double mn = 10000000001, mx = 0; cin >> n >> x0 >> y0; cin >> x1 >> y1; xstart = x1; ystart = y1; for (int i = 0; i < n - 1; i++) { x2 = x1; y2 = y1; cin >> x1 >> y1; if (check(x0, y0, x1, y1, x2, y2)) { mn = min(mn, len(x0, y0, x1, y1, x2, y2)); mx = max(mx, sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))); } else { mn = min(mn, sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))); mx = max(mx, sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))); } } x2 = x1; y2 = y1; x1 = xstart; y1 = ystart; if (check(x0, y0, x1, y1, x2, y2)) { mn = min(mn, len(x0, y0, x1, y1, x2, y2)); mx = max(mx, sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))); } else { mn = min(mn, sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))); mx = max(mx, sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0))); } printf("%.6f", PI * mx * mx - PI * mn * mn); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; const long double pi = acos(-1.0); struct point { long double x, y; point(long double px, long double py) { x = px, y = py; } point() {} } p[maxn]; point operator-(const point &p1, const point &p2) { return point(p2.x - p1.x, p2.y - p1.y); } long double dot(point a, point b) { return a.x * b.x + a.y * b.y; } long double cross(point a, point b) { return a.x * b.y - a.y * b.x; } long double dis2(point a, point b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } int main() { long double n; point pt; cin >> n >> pt.x >> pt.y; for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y; long double dmax = 0, dmin = 1e18; for (int i = 0; i < n; i++) { int j = (i == n - 1 ? 0 : i + 1); point ap = pt - p[i], ab = p[j] - p[i]; point bp = pt - p[j], ba = p[i] - p[j]; dmax = max(dmax, dis2(p[i], pt)); if (dot(ap, ab) < 0) { dmin = min(dmin, dis2(p[i], pt)); continue; } if (dot(bp, ba) < 0) { dmin = min(dmin, dis2(p[j], pt)); continue; } long double s = fabs((double)cross(ap, ab) * cross(ap, ab) / dis2(p[i], p[j])); dmin = min(dmin, s); } cout << fixed << setprecision(20) << pi * (dmax - dmin) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_V = 100005, inf = 99999999; double X0, Y0, PI = 3.141592653589793; inline double GetR(const double &x, const double &y) { return sqrt((x - X0) * (x - X0) + (y - Y0) * (y - Y0)); } double Abs(double x) { if (x >= 0) return x; else return -x; } double GetminR(double x1, double y1, double x2, double y2) { double A = (y2 - y1), B = (x1 - x2), C = (y1 - y2) * x1 + (x2 - x1) * y1; double d = Abs(A * X0 + B * Y0 + C) / sqrt(A * A + B * B); double ax01 = x1 - X0, ay01 = y1 - Y0, ax12 = x2 - x1, ay12 = y2 - y1, ax02 = x2 - X0, ay02 = y2 - Y0; double cos1 = ax01 * ax12 + ay01 * ay12, cos2 = -1 * (ax02 * ax12 + ay02 * ay12); if (cos1 <= 0 && cos2 <= 0) { return d; } else return GetR(x2, y2); } int main() { int n; scanf("%d%lf%lf", &n, &X0, &Y0); double Rmax = 0, Rmin = 1e9, x, y, r, x1, y1, xl, yl; scanf("%lf%lf", &x1, &y1); Rmax = max(Rmax, GetR(x1, y1)); xl = x1; yl = y1; for (int i = 1; i < n; i++) { scanf("%lf%lf", &x, &y); r = GetR(x, y); if (r > Rmax) Rmax = r; Rmin = min(Rmin, GetminR(xl, yl, x, y)); xl = x; yl = y; } Rmin = min(Rmin, GetminR(xl, yl, x1, y1)); double ans = PI * (Rmax * Rmax - Rmin * Rmin); printf("%.18lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; class point { public: double x, y; double dis(point& p); }; double x[100000]; const double PI = acos(-1.0); double dish(point& p, point& a, point& b) { double aa = a.dis(p), bb = b.dis(p), cc = a.dis(b); double q = (aa + bb + cc) / 2; double s = sqrt(q * (q - aa) * (q - bb) * (q - cc)); double h = 2 * s / cc; return h; } point abc[1000000]; int main() { int n, i; cin >> n; point p; cin >> p.x >> p.y; for (i = 0; i < n; i++) { cin >> abc[i].x >> abc[i].y; x[i] = abc[i].dis(p); } abc[i] = abc[0]; sort(x, x + n); double r1 = x[0], r2 = x[n - 1]; for (int j = 0; j <= n; j++) { double aa = abc[j].dis(p), bb = abc[j + 1].dis(p), cc = abc[j].dis(abc[j + 1]); if (aa * aa + cc * cc <= bb * bb || cc * cc + bb * bb <= aa * aa) continue; double h = dish(p, abc[j], abc[j + 1]); if (h < r1) r1 = h; } printf("%.20f\n", PI * (r2 * r2 - r1 * r1)); return 0; } double point::dis(point& p) { return sqrt(((x - p.x) * (x - p.x) + (y - p.y) * (y - p.y))); }
#include <bits/stdc++.h> using namespace std; const int N = 10000000; const double pi = 3.14159265358979; double x[N], y[N]; double R, r; int n; double dis(int i) { return sqrt((x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[i] - y[0])); } void seg_dis(int i) { int j = i + 1; double d = dis(i); R = max(R, d); r = min(r, d); if (i == n) j = 1; double x1 = x[0] - x[i], x2 = x[j] - x[i], y1 = y[0] - y[i], y2 = y[j] - y[i]; double iner = x1 * x2 + y1 * y2; if (iner < 0) return; if (iner > x2 * x2 + y2 * y2) return; d = abs(x1 * y2 - x2 * y1); d /= sqrt(x2 * x2 + y2 * y2); r = min(d, r); } int main() { cin >> n; cin >> x[0] >> y[0]; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } R = -1, r = 10000000000; for (int i = 1; i <= n; i++) { seg_dis(i); } cout << fixed << setprecision(20) << (R * R - r * r) * pi; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; const double eps = 1e-10; int n; int dcmp(double x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; } 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() { if (dcmp(x) == 0) x = 0; if (dcmp(y) == 0) y == 0; printf("%.2f %.2f", x, y); } void Rotate(double rad) { double dx = x * cos(rad) - y * sin(rad), dy = x * sin(rad) + y * cos(rad); x = dx; y = dy; } } poly[maxn], P; Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); } Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); } Point operator*(Point A, double p) { return Point(A.x * p, A.y * p); } Point operator/(Point A, double p) { return Point(A.x / p, A.y / p); } bool operator==(Point A, Point B) { return dcmp(A.x - B.x) == 0 && dcmp(A.y - B.y) == 0; } bool operator<(Point A, Point B) { return A.x < B.x || (A.x == B.x && A.y < B.y); } double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } double Length(Point A) { return sqrt(Dot(A, A)); } double Angle(Point A, Point B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Point A, Point B) { return A.x * B.y - B.x * A.y; } double TriangleArea(Point A, Point B, Point C) { return fabs(Cross(C - A, B - A) / 2); } double Distance(Point P, Point A, Point B) { if (A == B) return Length(P - A); Point u = B - A, v = P - A, w = P - B; if (dcmp(Dot(u, v)) < 0) return Length(v); if (dcmp(Dot(u, w)) > 0) return Length(w); return fabs(Cross(u, v) / Length(u)); } void work() { scanf("%d", &n); P.read(); double x = 0, y = 1e9; for (int i = 1; i <= n; ++i) poly[i].read(); poly[n + 1] = poly[1]; for (int i = 1; i <= n; ++i) x = max(x, Length(P - poly[i])); for (int i = 1; i <= n; ++i) y = min(y, Distance(P, poly[i], poly[i + 1])); double S = M_PI * (x * x - y * y); printf("%lf", S); } int main() { work(); return 0; }
#include <bits/stdc++.h> using namespace std; const double esp = 1e-7; double dis(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2 * 1.0) * (x1 - x2 * 1.0) + (y1 - y2 * 1.0) * (y1 - y2 * 1.0)); } double dis2line(double x, double y, double x1, double y1, double x2, double y2) { double dbLen1, dbLen2, dbLen3; double dbAng, dbAng1, dbAng2; dbLen1 = dis(x, y, x1, y1); if (dbLen1 < esp) return 0.0; dbLen2 = dis(x, y, x2, y2); if (dbLen2 < esp) return 0.0; dbLen3 = dis(x1, y1, x2, y2); if (dbLen3 < esp) return dbLen1; if (dbLen1 < dbLen2) { if (y1 == y2) { if (x1 < x2) dbAng1 = 0.0; else dbAng1 = 3.1415926535897932384626; } else { dbAng1 = acos((x2 - x1) / dbLen3); if (y1 > y2) dbAng1 = 2 * 3.1415926535897932384626 - dbAng1; } dbAng2 = acos((x - x1) / dbLen1); if (y1 > y) dbAng2 = 2 * 3.1415926535897932384626 - dbAng2; dbAng = dbAng2 - dbAng1; if (dbAng < esp) dbAng = -dbAng; if (dbAng > 3.1415926535897932384626) dbAng = 2 * 3.1415926535897932384626 - dbAng; if (dbAng > 3.1415926535897932384626 / 2) return dbLen1; else return (dbLen1 * sin(dbAng)); } else { if (y1 == y2) { if (x1 < x2) dbAng1 = 3.1415926535897932384626; else dbAng1 = 0.0; } else { dbAng1 = acos((x1 - x2) / dbLen3); if (y2 > y1) dbAng1 = 2 * 3.1415926535897932384626 - dbAng1; } dbAng2 = acos((x - x2) / dbLen2); if (y2 > y) dbAng2 = 2 * 3.1415926535897932384626 - dbAng2; dbAng = dbAng2 - dbAng1; if (dbAng < esp) dbAng = -dbAng; if (dbAng > 3.1415926535897932384626) dbAng = 2 * 3.1415926535897932384626 - dbAng; if (dbAng > 3.1415926535897932384626 / 2) return dbLen2; else return (dbLen2 * sin(dbAng)); } } struct node { double x, y; } p[100000 + 100]; int main() { int n; double px, py; double mindis = -1; double maxdis = -1; scanf("%d%lf%lf", &n, &px, &py); for (int i = 0; i < n; i++) { double x, y; scanf("%lf%lf", &x, &y); p[i].x = x; p[i].y = y; double dist = dis(p[i].x, p[i].y, px * 1.0, py * 1.0); if (maxdis < 0 || dist > maxdis) maxdis = dist; if (mindis < 0 || dist < mindis) mindis = dist; if (i > 0) { dist = dis2line(px * 1.0, py * 1.0, x, y, p[i - 1].x, p[i - 1].y); if (maxdis < 0 || dist > maxdis) maxdis = dist; if (mindis < 0 || dist < mindis) mindis = dist; } } double dist = dis2line(px * 1.0, py * 1.0, p[0].x, p[0].y, p[n - 1].x, p[n - 1].y); if (maxdis < 0 || dist > maxdis) maxdis = dist; if (mindis < 0 || dist < mindis) mindis = dist; printf("%.8lf\n", (maxdis * maxdis * 3.1415926535897932384626 - mindis * mindis * 3.1415926535897932384626)); return 0; }
#include <bits/stdc++.h> using namespace std; enum STATE { IN, OUT, BOUNDRY }; complex<double> polygon[100005]; complex<double> centre; int n; double pointLineDist(const complex<double>& a, const complex<double>& b, const complex<double>& p) { return fabs(((conj(((b) - (a))) * (((p) - (a)))).imag()) / ((double)hypot((((b) - (a))).imag(), (((b) - (a))).real()))); } double pointSegmentDist(const complex<double>& a, const complex<double>& b, const complex<double>& p) { if (((conj(((b) - (a))) * (((p) - (a)))).real()) < 1e-9) return ((double)hypot((((p) - (a))).imag(), (((p) - (a))).real())); if (((conj(((a) - (b))) * (((p) - (b)))).real()) < 1e-9) return ((double)hypot((((p) - (b))).imag(), (((p) - (b))).real())); return pointLineDist(a, b, p); } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; int x, y; cin >> x >> y; centre = complex<double>(x, y); for (int i = 0; i < n; ++i) { cin >> x >> y; polygon[i] = complex<double>(x, y); } polygon[n] = polygon[0]; double r2 = 0, r1 = 1e7; for (int i = 0; i < n; ++i) { r2 = max(r2, hypot(polygon[i].real() - centre.real(), polygon[i].imag() - centre.imag())); r1 = min(r1, pointSegmentDist(polygon[i], polygon[i + 1], centre)); } cout << fixed << setprecision(6) << acos(-1) * (r2 * r2 - r1 * r1); }
#include <bits/stdc++.h> using namespace std; double X[100000 + 5]; double Y[100000 + 5]; int main() { int n; double sx, sy; scanf("%d%lf%lf", &n, &sx, &sy); for (int i = 1; i <= n; i++) { double a, b; scanf("%lf%lf", &a, &b); X[i] = a - sx; Y[i] = b - sy; } X[n + 1] = X[1]; Y[n + 1] = Y[1]; double Max, Min; Max = X[1] * X[1] + Y[1] * Y[1]; Min = X[1] * X[1] + Y[1] * Y[1]; for (int i = 2; i <= n; i++) { double a = X[i] * X[i] + Y[i] * Y[i]; Max = max(a, Max); Min = min(a, Min); } for (int i = 2; i <= n + 1; i++) { double a2, b2, c2; a2 = (X[i] - X[i - 1]) * (X[i] - X[i - 1]) + (Y[i] - Y[i - 1]) * (Y[i] - Y[i - 1]); b2 = X[i] * X[i] + Y[i] * Y[i]; c2 = X[i - 1] * X[i - 1] + Y[i - 1] * Y[i - 1]; if ((a2 + b2 > c2) && (a2 + c2 > b2)) { double result1 = 2 * (a2 * b2 + a2 * c2 + b2 * c2) - c2 * c2 - a2 * a2 - b2 * b2; double result2 = result1 / (4 * a2); Min = min(Min, result2); } } double ans; ans = acos(-1.0) * (Max - Min); printf("%f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } double mn = 1000000000, mx = -1000000000; int n; double px, py; struct P { double x, y; friend double dis(P a) { return sqrt(a.x * a.x + a.y * a.y); } friend P operator-(P a, P b) { return (P){a.x - b.x, a.y - b.y}; } friend double operator*(P a, P b) { return a.x * b.y - a.y * b.x; } friend double operator/(P a, P b) { return a.x * b.x + a.y * b.y; } } a[100005]; double dis(P a, P b, P c) { if ((c - a) / (b - a) > 0 && (c - b) / (a - b) > 0) return abs((a - b) * (c - b)) / dis(a - b); else return min(dis(a - c), dis(b - c)); } int main() { n = read(); px = read(); py = read(); for (int i = 1; i <= n; i++) a[i].x = read(), a[i].y = read(); a[n + 1] = a[1]; for (int i = 1; i <= n; i++) { double d1 = dis(a[i], a[i + 1], (P){px, py}), d2 = dis(a[i] - (P){px, py}); mn = min(d1, mn); mx = max(d2, mx); } double ans = acos(-1) * (mx * mx - mn * mn); printf("%.10lf", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793; const double inf = 1LL << 60; const double eps = 1E-8; long long dist(long long x, long long y, long long k, long long l) { return (double)(x - k) * (x - k) + (y - l) * (y - l); } double dist1(double x, double y, double k, double l) { return sqrt((x - k) * (x - k) + (y - l) * (y - l)); } double shortest_dist(long long p, long long q, long long x1, long long y1, long long x2, long long y2) { long long res = abs((y2 - y1) * (p - x1) + (x2 - x1) * y1 - (x2 - x1) * q); return (double)res / sqrt(dist(x1, y1, x2, y2)); } bool check_point(long long p, long long q, long long x1, long long y1, long long x2, long long y2) { double x = ((y2 - y1) * (p - x1) + (x2 - x1) * y1 - (x2 - x1) * q) * (-1); x /= (dist(x1, y1, x2, y2)); x *= (y2 - y1); x += p; double y = ((y2 - y1) * (p - x1) + (x2 - x1) * y1 - (x2 - x1) * q) * (-1); y /= (dist(x1, y1, x2, y2)); y *= (x1 - x2); y += q; ; if (dist1(x1, y1, x, y) + dist1(x2, y2, x, y) - dist1(x1, y1, x2, y2) > eps) return false; else return true; } int main() { long long n, p, q, k, l, i; double max, res, min, dist_1, dist2, dist3; vector<pair<long long, long long> > pts; cin >> n >> p >> q; max = 0.0; for (i = 0; i < n; ++i) { cin >> k >> l; pts.push_back(make_pair(k, l)); res = dist1(p, q, k, l); if (res > max) max = res; } min = inf; for (i = 0; i < n - 1; ++i) { dist_1 = shortest_dist(p, q, pts[i].first, pts[i].second, pts[i + 1].first, pts[i + 1].second); dist2 = dist1(p, q, pts[i].first, pts[i].second); dist3 = dist1(p, q, pts[i + 1].first, pts[i + 1].second); if (check_point(p, q, pts[i].first, pts[i].second, pts[i + 1].first, pts[i + 1].second)) { if (min > dist_1) min = dist_1; } else { if (min > dist2) min = dist2; if (min > dist3) min = dist3; } } dist_1 = shortest_dist(p, q, pts[n - 1].first, pts[n - 1].second, pts[0].first, pts[0].second); dist2 = dist1(p, q, pts[n - 1].first, pts[n - 1].second); dist3 = dist1(p, q, pts[0].first, pts[0].second); if (check_point(p, q, pts[n - 1].first, pts[n - 1].second, pts[0].first, pts[0].second)) { if (min > dist_1) min = dist_1; } else { if (min > dist2) min = dist2; if (min > dist3) min = dist3; } printf("%.7lf\n", (double)PI * ((max * max) - (min * min))); return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int sgn(double x) { return x < -eps ? -1 : x > eps; } struct Point; struct Point { double x, y; void in() { scanf("%lf%lf", &x, &y); } void print() { printf("%.2lf %.2lf\n", x, y); } Point(double x = 0, double y = 0) : x(x), y(y) {} inline Point rotate(double ang) { return Point(x * cos(ang) - y * sin(ang), x * sin(ang) + y * cos(ang)); } inline double dot(const Point &a) { return x * a.x + y * a.y; } inline bool operator==(const Point &a) const { return sgn(x - a.x) == 0 && sgn(y - a.y) == 0; } inline bool operator<(const Point &a) const { return sgn(x - a.x) < 0 || sgn(x - a.x) == 0 && sgn(y - a.y) < 0; } inline Point operator+(const Point &a) const { return Point(x + a.x, y + a.y); } inline Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); } inline double operator*(const Point &a) const { return x * a.y - y * a.x; } inline Point operator*(double t) const { return Point(x * t, y * t); } inline Point operator/(double t) { return Point(x / t, y / t); } inline double vlen() { return sqrt(x * x + y * y); } inline Point norm() { return Point(-y, x); } }; struct Cir { Point ct; double r; void in() { ct.in(); scanf("%lf", &r); } }; struct Seg { Point s, e; Seg() {} Seg(Point s, Point e) : s(s), e(e) {} void in() { s.in(); e.in(); } }; struct Line { int a, b, c; }; inline bool cmpyx(const Point &a, const Point &b) { if (a.y != b.y) { return a.y < b.y; } return a.x < b.x; } double cross(Point a, Point b, Point c) { return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y); } bool same_dir(Point a, Point b) { return sgn(a.x * b.y - b.x * a.y) == 0 && sgn(a.x * b.x) >= 0 && sgn(a.y * b.y) >= 0; } bool dot_on_seg(Point p, Seg L) { return sgn((L.s - p) * (L.e - p)) == 0 && sgn((L.s - p).dot(L.e - p)) <= 0; } double ppdis(Point a, Point b) { return sqrt((a - b).dot(a - b)); } double pldis(Point p, Point l1, Point l2) { return fabs(cross(p, l1, l2)) / ppdis(l1, l2); } double pldis(Point p, Line ln) { return fabs(ln.a * p.x + ln.b * p.y + ln.c) / sqrt(ln.a * ln.a + ln.b * ln.b); } bool point_in_circle(Point &a, Cir cr) { return sgn(ppdis(a, cr.ct) - cr.r) <= 0; } bool intersect(Point P, Point v, Point Q, Point w, Point &ret) { Point u = P - Q; if (sgn(v * w) == 0) return false; double t = w * u / (v * w); ret = P + v * t; return true; } Point intersect(Point P, Point v, Point Q, Point w) { Point ret; Point u = P - Q; if (sgn(v * w) == 0) return false; double t = w * u / (v * w); ret = P + v * t; return ret; } Point disptoline(Point p, Seg l) { return fabs(cross(p, l.s, l.e)) / ppdis(l.s, l.e); } Point ptoline(Point p, Seg l) { Point vec = l.s - l.e; return intersect(p, vec.norm(), l.s, vec); } Point ptoseg(Point p, Seg l) { Point norm = (l.s - l.e).norm(); if (sgn(norm * (p - l.s)) * sgn(norm * (p - l.e)) > 0) { double sa = ppdis(p, l.s); double sb = ppdis(p, l.e); return sgn(sa - sb) < 0 ? l.s : l.e; } return intersect(p, norm, l.s, l.e - l.s); } Point p[100010]; int main() { int n; Point p0; scanf("%d", &n); p0.in(); for (int i = 0; i < n; i++) { p[i].in(); } double mx = 0, mi = 1e100; for (int i = 0; i < n; i++) { mx = max(mx, ppdis(p0, p[i])); mi = min(mi, ppdis(p0, ptoseg(p0, Seg(p[i], p[(i + 1) % n])))); } printf("%.8f\n", (mx * mx - mi * mi) * acos(-1.0)); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; const double PI = 3.1415926535897932384626433832795; const double INF = 1e100; int n; double px, py; double mmax = -INF, mmin = INF; double x[MAXN + 10], y[MAXN + 10]; int main() { scanf("%d%lf%lf", &n, &px, &py); double len; for (int i = 1; i <= n; ++i) scanf("%lf%lf", x + i, y + i); for (int i = 1; i <= n; ++i) { int a = i, b = i + 1; if (b > n) b = 1; len = (px - x[i]) * (px - x[i]) + (py - y[i]) * (py - y[i]); mmax = max(mmax, len); mmin = min(mmin, len); double x_1 = x[a] - x[b], y_1 = y[a] - y[b], x_2 = px - x[b], y_2 = py - y[b]; if (x_1 * x_2 + y_1 * y_2 > 0) { x_1 = x[b] - x[a]; y_1 = y[b] - y[a]; x_2 = px - x[a]; y_2 = py - y[a]; if (x_1 * x_2 + y_1 * y_2 > 0) { mmin = min(mmin, (y_1 * x_2 - x_1 * y_2) * (y_1 * x_2 - x_1 * y_2) / (x_1 * x_1 + y_1 * y_1)); } } } printf("%.18lf", PI * (mmax - mmin)); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 9; const double pie = 3.14159265358979323846; const long long int INF = 1e18 + 9; double vec[MAX_N]; pair<double, double> point[MAX_N]; int main() { int N, M, T; double X, Y; while (~scanf("%d%lf%lf", &N, &X, &Y)) { double minn = INF; double maxn = 0; for (int i = 0; i < N; i++) { double a, b; scanf("%lf%lf", &a, &b); point[i] = make_pair(a, b); vec[i] = sqrt((X - a) * (X - a) + (Y - b) * (Y - b)); if (maxn < vec[i]) maxn = vec[i]; } for (int i = 0; i < N; i++) { double A = vec[i]; double B = sqrt((point[i].first - point[(i + 1) % N].first) * (point[i].first - point[(i + 1) % N].first) + (point[i].second - point[(i + 1) % N].second) * (point[i].second - point[(i + 1) % N].second)); double C = vec[(i + 1) % N]; if ((A * A + B * B - C * C) <= 0 || (B * B + C * C - A * A) <= 0) { double temp = min(A, C); minn = min(minn, temp); } else { double p = (A + B + C) / 2.0; double S = sqrt(p * (p - A) * (p - B) * (p - C)); double h = 2.0 * S / B; minn = min(minn, h); } } printf("%.12lf\n", pie * (maxn * maxn - minn * minn)); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e15; const int N = 1e5 + 5; double eps = 1e-15; struct node { double x; double y; } a[N]; double Sqrt(double n) { double mid; double l = 0, r = 1e14; while (r - l >= eps) { mid = (l + r) / 2; if (mid * mid < n) l = mid; else r = mid; } return mid; } int main() { int n; double x, y; scanf("%d%lf%lf", &n, &x, &y); double d1 = INF, d2 = 0; for (int i = 0; i < n; i++) { cin >> a[i].x >> a[i].y; } for (int i = 0; i < n - 1; i++) { double l1 = (a[i].x - x) * (a[i].x - x) + (a[i].y - y) * (a[i].y - y); double l2 = (a[i + 1].x - x) * (a[i + 1].x - x) + (a[i + 1].y - y) * (a[i + 1].y - y); double l3 = (a[i + 1].x - a[i].x) * (a[i + 1].x - a[i].x) + (a[i + 1].y - a[i].y) * (a[i + 1].y - a[i].y); d2 = max(d2, max(l1, l2)); d1 = min(d1, min(l1, l2)); if (l1 + l3 < l2 || l2 + l3 < l1) continue; l1 = sqrt(l1); l2 = sqrt(l2); l3 = sqrt(l3); double p = (l1 + l2 + l3) / 2; double s = sqrt(p * (p - l1) * (p - l2) * (p - l3)); double d = s * 2 / l3; d1 = min(d * d, d1); } double l1 = (a[0].x - x) * (a[0].x - x) + (a[0].y - y) * (a[0].y - y); double l2 = (a[n - 1].x - x) * (a[n - 1].x - x) + (a[n - 1].y - y) * (a[n - 1].y - y); double l3 = (a[n - 1].x - a[0].x) * (a[n - 1].x - a[0].x) + (a[n - 1].y - a[0].y) * (a[n - 1].y - a[0].y); d2 = max(d2, max(l1, l2)); d1 = min(d1, min(l1, l2)); if (l1 + l3 >= l2 && l2 + l3 >= l1) { l1 = sqrt(l1); l2 = sqrt(l2); l3 = sqrt(l3); double p = (l1 + l2 + l3) / 2.0; double s = sqrt(p * (p - l1) * (p - l2) * (p - l3)); double d = s * 2.0 / l3; d1 = min(d * d, d1); } double ans = acos(-1.0) * d2 - acos(-1.0) * d1; printf("%.18lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using R = double; using P = complex<R>; const R EPS = 1e-9; const R PI = acos((R)(-1)); int sgn(R a) { if (a < -EPS) return -1; if (a > EPS) return 1; return 0; } int sgn(R a, R b) { return sgn(b - a); } bool near(const P &a, const P &b) { return !sgn(abs(a - b)); } bool lessP(const P &l, const P &r) { if (sgn(l.real(), r.real())) return l.real() < r.real(); if (sgn(l.imag(), r.imag())) return l.imag() < r.imag(); return false; } R cross(P a, P b) { return a.real() * b.imag() - a.imag() * b.real(); } R dot(P a, P b) { return a.real() * b.real() + a.imag() * b.imag(); } int ccw(P a, P b, P c) { assert(!near(a, b)); if (near(a, c) || near(b, c)) return 0; int s = sgn(cross(b - a, c - a)); if (s) return s; if (dot(b - a, c - a) < 0) return 2; if (dot(a - b, c - b) < 0) return -2; return 0; } struct L { P x, y; L() {} L(P x, P y) : x(x), y(y) {} }; P vec(const L &l) { return l.y - l.x; } R abs(const L &l) { return abs(vec(l)); } R arg(const L &l) { return arg(vec(l)); } R distLP(const L &l, const P &p) { return abs(cross(vec(l), p - l.x) / abs(vec(l))); } R distSP(const L &s, const P &p) { P s2 = vec(s) * P(0, 1); if (ccw(s.x, s.x + s2, p) == 1) return abs(s.x - p); if (ccw(s.y, s.y + s2, p) == -1) return abs(s.y - p); return min(min(abs(s.x - p), abs(s.y - p)), distLP(s, p)); } using Pol = vector<P>; template <class C> P cu(const C &p, int i) { int s = p.size(); return p[(i % s + s) % s]; }; template <class C> int contains(const C &pol, P p) { int in = -1; for (int i = 0; i < (int)pol.size(); i++) { P a = cu(pol, i) - p, b = cu(pol, i + 1) - p; if (ccw(a, b, P(0, 0)) == 0) return 1; if (imag(a) > imag(b)) swap(a, b); if (imag(a) <= 0 && 0 < imag(b)) { if (cross(a, b) < 0) in *= -1; } } return in + 1; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20); int n; cin >> n; R x, y; cin >> x >> y; P st = P(x, y); Pol p; for (int i = 0; i < n; i++) { R u, v; cin >> u >> v; p.push_back(P(u, v)); } R mi = 1e10, ma = -1; for (int i = 0; i < n; i++) { L l = L(cu(p, i), cu(p, i + 1)); mi = min(mi, distSP(l, st)); ma = max(ma, abs(p[i] - st)); } if (contains(p, st)) mi = 0; cout << (ma * ma - mi * mi) * PI << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct point { double x, y; } rec[100005]; double cross(point p, point p1) { return sqrt((p1.x - p.x) * (p1.x - p.x) + (p1.y - p.y) * (p1.y - p.y)); } int main() { point firP; int t; while (scanf("%d%lf%lf", &t, &firP.x, &firP.y) != EOF) { for (int i = 0; i < t; i++) scanf("%lf%lf", &rec[i].x, &rec[i].y); rec[t] = rec[0]; double maxL = -1, minL = 99999999; for (int i = 0; i < t; i++) { double a = cross(firP, rec[i]); double b = cross(firP, rec[i + 1]); double c = cross(rec[i], rec[i + 1]); maxL = max(maxL, max(a, b)); if ((c * c + b * b) <= a * a) minL = min(minL, b); else if ((a * a + c * c) <= b * b) minL = min(minL, a); else { double p = (a + b + c) / 2.0; double s = sqrt(p * (p - a) * (p - b) * (p - c)); minL = min(minL, s * 2.0 / c); } } printf("%lf\n", acos(-1.0) * (maxL * maxL - minL * minL)); } return 0; }
#include <bits/stdc++.h> using namespace std; int n; double mn, mx; double Px, Py; double x[100002]; double y[100002]; double f(double x1, double y1, double x2, double y2, int cnt) { double d1 = 0; d1 += (Px - x1) * (Px - x1); d1 += (Py - y1) * (Py - y1); double d2 = 0; d2 += (Px - x2) * (Px - x2); d2 += (Py - y2) * (Py - y2); if (cnt == 300) return min(d1, d2); double dx = (x2 - x1) / 3.0; double dy = (y2 - y1) / 3.0; if (d1 < d2) return f(x1, y1, x2 - dx, y2 - dy, cnt + 1); else return f(x1 + dx, y1 + dy, x2, y2, cnt + 1); } int main() { scanf("%d%lf%lf", &n, &Px, &Py); for (int i = 0; i < n; i++) { scanf("%lf%lf", &x[i], &y[i]); double dx = Px - x[i]; double dy = Py - y[i]; double dist = dx * dx + dy * dy; if (!i) mn = mx = dist; mn = min(mn, dist); mx = max(mx, dist); } for (int i = 0; i < n; i++) mn = min(mn, f(x[i], y[i], x[(i + 1) % n], y[(i + 1) % n], 0)); printf("%.10lf\n", M_PI * (mx - mn)); }
#include <bits/stdc++.h> using namespace std; long long int n; pair<long long int, long long int> p, arr[100005], temp; double rmin, rmax; double dist(pair<long long int, long long int> a) { double ret; ret = (a.first * a.first) + (a.second * a.second); return sqrt(ret); } pair<long long int, double> intersect(pair<long long int, long long int> a1, pair<long long int, long long int> a2) { long long int v0v2 = ((-1) * a1.first * (a2.first - a1.first)) + ((-1) * a1.second * (a2.second - a1.second)); long long int v2v2 = ((a2.first - a1.first) * (a2.first - a1.first)) + ((a2.second - a1.second) * (a2.second - a1.second)); if (v0v2 > 0 && v0v2 < v2v2) { double temp = (double)v0v2 / (double)v2v2; double retx, rety; retx = a1.first + (temp * (a2.first - a1.first)); rety = a1.second + (temp * (a2.second - a1.second)); return make_pair(1, (double)(sqrt((retx * retx) + (rety * rety)))); } else return make_pair(0, 0.0); } void solve(pair<long long int, long long int> a1, pair<long long int, long long int> a2) { double darr[5]; darr[0] = dist(a1); darr[1] = dist(a2); pair<long long int, double> val = intersect(a1, a2); if (val.first == 1) { darr[2] = val.second; sort(darr, darr + 3); rmin = min(rmin, darr[0]); rmax = max(rmax, darr[2]); } else { sort(darr, darr + 2); rmin = min(rmin, darr[0]); rmax = max(rmax, darr[1]); } return; } int main() { rmin = 10000000000, rmax = -1; cin >> n >> p.first >> p.second; for (long long int i = 0; i < n; i++) { ; scanf("%lld", &temp.first); ; ; scanf("%lld", &temp.second); ; temp.first -= p.first; temp.second -= p.second; arr[i] = temp; } solve(arr[0], arr[n - 1]); for (long long int i = 1; i < n; i++) { solve(arr[i], arr[i - 1]); } double ans = (M_PI * (rmax - rmin) * (rmax + rmin)); cout << setprecision(30) << (M_PI * (rmax - rmin) * (rmax + rmin)) << endl; ; return 0; }
#include <bits/stdc++.h> using namespace std; pair<double, double> operator-(const pair<double, double> &a, const pair<double, double> &b) { return {a.first - b.first, a.second - b.second}; } struct garis { double first; double second; double c; }; double FindDistanceToSegment(double x1, double y1, double x2, double y2, double pointX, double pointY) { double diffX = x2 - x1; float diffY = y2 - y1; if ((diffX == 0) && (diffY == 0)) { diffX = pointX - x1; diffY = pointY - y1; return sqrt(diffX * diffX + diffY * diffY); } float t = ((pointX - x1) * diffX + (pointY - y1) * diffY) / (diffX * diffX + diffY * diffY); if (t < 0) { diffX = pointX - x1; diffY = pointY - y1; } else if (t > 1) { diffX = pointX - x2; diffY = pointY - y2; } else { diffX = pointX - (x1 + t * diffX); diffY = pointY - (y1 + t * diffY); } return sqrt(diffX * diffX + diffY * diffY); } int main() { int n; double first, second; cin >> n >> first >> second; vector<pair<double, double> > v; for (int i = 0; i < n; i++) { double a, b; cin >> a >> b; v.push_back(make_pair(a, b)); } double kecil = 1e13; double besar = -1e13; for (int i = 0; i < v.size(); i++) { pair<double, double> ini = make_pair(first, second) - v[i]; double jarak = ini.first * ini.first + ini.second * ini.second; jarak = sqrt(jarak); if (jarak < kecil) { kecil = jarak; } if (jarak > besar) { besar = jarak; } } vector<struct garis> g; for (int i = 0; i < v.size() - 1; i++) { double jarak = FindDistanceToSegment(v[i].first, v[i].second, v[i + 1].first, v[i + 1].second, first, second); if (jarak < kecil) { kecil = jarak; } } double jarak = FindDistanceToSegment(v[v.size() - 1].first, v[v.size() - 1].second, v[0].first, v[0].second, first, second); if (jarak < kecil) { kecil = jarak; } double luas = acos(-1) * (besar * besar - kecil * kecil); printf("%.6lf\n", luas); }
#include <bits/stdc++.h> using namespace std; long long px, py; long long n, x[100005], y[100005]; long double ternary(long long i, long long j) { long double x1, y1, x2, y2; long double x0 = x[i], y0 = y[i], x3 = x[j], y3 = y[j]; long double lx, ly; for (long long k = 0; k < 50; ++k) { lx = (x3 - x0); ly = y3 - y0; x1 = x0 + lx / 3; x2 = x3 - lx / 3; y1 = y0 + ly / 3; y2 = y3 - ly / 3; lx = (x1 - px) * (x1 - px) + (y1 - py) * (y1 - py); ly = (x2 - px) * (x2 - px) + (y2 - py) * (y2 - py); if (lx < ly) x3 = x2, y3 = y2; else x0 = x1, y0 = y1; } return lx; } int main() { long double mx = 0, mn = 1e18; cin >> n >> px >> py; for (long long i = 0; i < n; ++i) { cin >> x[i] >> y[i]; long double r = ((x[i] - px) * (x[i] - px) + (y[i] - py) * (y[i] - py)); mx = max(mx, r); } x[n] = x[0]; y[n] = y[0]; for (long long i = 1; i <= n; ++i) { mn = min(mn, ternary(i, i - 1)); } cout << setprecision(12) << fixed; cout << acos(-1) * (mx - mn); }
#include <bits/stdc++.h> using namespace std; long double dist(long double x1, long double y1, long double x2, long double y2, long double x3, long double y3) { long double px = x2 - x1; long double py = y2 - y1; long double something = px * px + py * py; long double u = ((x3 - x1) * px + (y3 - y1) * py) / something; if (u > 1) u = 1; else if (u < 0) u = 0; long double x = x1 + u * px; long double y = y1 + u * py; long double dx = x - x3; long double dy = y - y3; long double dist = sqrt(dx * dx + dy * dy); return dist; } int main() { int n; long double x, y; cin >> n >> x >> y; vector<pair<long double, long double> > v; long double mx = 0.0, mn = 1000000000000000000.0; for (int i = 0; i < n; i++) { long double a, b; cin >> a >> b; v.push_back(make_pair(a, b)); mx = max(mx, (x - a) * (x - a) + (y - b) * (y - b)); } for (int i = 1; i < v.size(); i++) { mn = min(mn, dist(v[i].first, v[i].second, v[i - 1].first, v[i - 1].second, x, y)); } mn = min( mn, dist(v[0].first, v[0].second, v[n - 1].first, v[n - 1].second, x, y)); mx = sqrt(mx); cout << setprecision(10) << fixed << 3.141592653589793 * (mx * mx - mn * mn); }
#include <bits/stdc++.h> using namespace std; inline constexpr long double sq(long double x) { return x * x; } inline constexpr long double dist(const pair<int, int> &p1, const pair<int, int> &p2) { return sqrt(sq(p1.first - p2.first) + sq(p1.second - p2.second)); } int main() { int n; pair<int, int> p; cin >> n >> p.first >> p.second; vector<pair<int, int> > v(n); for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second; long double r1 = dist(v[0], p), r2 = dist(v[0], p); for (pair<int, int> pp : v) r2 = max(r2, dist(pp, p)); for (int i = 0; i < n; i++) { pair<int, int> p1 = v[i]; pair<int, int> p2 = v[(i + 1) % n]; long double x0 = p.first; long double y0 = p.second; long double x1 = p1.first; long double y1 = p1.second; long double x2 = p2.first; long double y2 = p2.second; long double a = sq(x1 - x2) + sq(y1 - y2); long double b = 2 * ((x2 - x0) * (x1 - x2) + (y2 - y0) * (y1 - y2)); long double c = sq(x2 - x0) + sq(y2 - y0); long double p = -b / a / 2; if (0 < p && p < 1) { long double q = 1 - p; long double x3 = p * x1 + q * x2 - x0; long double y3 = p * y1 + q * y2 - y0; long double d = sqrtl(sq(x3) + sq(y3)); r1 = min(r1, d); } } long double s = acosl(-1) * (sq(r2) - sq(r1)); cout << setprecision(18) << fixed << s << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 23; const int MOD = 1e9 + 9; const int MAXN = 1e5 + 100; const double PI = 3.141592653589793238462643383279502884; struct point { int x, y; point operator-(const point &rhs) { point p; p.x = x - rhs.x; p.y = y - rhs.y; return p; } long long operator*(const point &rhs) { return x * 1LL * rhs.x + y * 1LL * rhs.y; } long long operator^(const point &rhs) { return x * 1LL * rhs.y - y * 1LL * rhs.x; } }; double linePointDist(point A, point B, point C, bool isSegment) { double dist = ((B - A) ^ (C - A)) / sqrt((B - A) * (B - A)); if (isSegment) { long long dot1 = (C - B) * (B - A); if (dot1 > 0) return sqrt((B - C) * (B - C)); long long dot2 = (C - A) * (A - B); if (dot2 > 0) return sqrt((A - C) * (A - C)); } return fabs(dist); } int main() { ios_base::sync_with_stdio(0); int n; double mx = -1, mn = 1e6 * 1LL * 1e6 + 1; point P, last, cur, first; cin >> n >> P.x >> P.y; cin >> first.x >> first.y; last = first; for (int i = 1; i < n; ++i) { cin >> cur.x >> cur.y; double ptdist = sqrt((P - cur) * (P - cur)); mx = max(mx, ptdist); double ldist = linePointDist(last, cur, P, true); mn = min(mn, ldist); last = cur; } double ptdist = sqrt((P - first) * (P - first)); mx = max(mx, ptdist); double ldist = linePointDist(cur, first, P, true); mn = min(mn, ldist); double ans = (mx * mx - mn * mn) * PI; cout.precision(numeric_limits<double>::max_digits10); cout << fixed << ans << "\n"; return 0; }
#include <bits/stdc++.h> const long double EPS = 1e-6; const long double PI = acos(-1); const int MOD = 1e9 + 7; using namespace std; struct Point { long double x, y; Point() { x = 0; y = 0; } Point(const long double& i, const long double& j) { x = i; y = j; } Point(const Point& pnt) { x = pnt.x; y = pnt.y; } void set(const Point& k) { x = k.x; y = k.y; } void set(const long double& kx, const long double& ky) { x = kx; y = ky; } } p[100001]; long double x, y; long double getDist(const Point& p1) { return ((x - p1.x) * 1ll * (x - p1.x)) + ((y - p1.y) * 1ll * (y - p1.y)); } long double getBest(const Point& p1, const Point& p2) { Point low(p1); Point high(p2); for (int i = 1; i <= 60; i++) { Point mid1((2 * low.x + high.x) / (3.0), (2 * low.y + high.y) / (3.0)); Point mid2((2 * high.x + low.x) / (3.0), (2 * high.y + low.y) / (3.0)); if (getDist(mid2) > getDist(mid1)) high.set(mid2); else low.set(mid1); } Point ans; ans.set((low.x + high.x) / 2, (low.y + high.y) / 2); return getDist(low); } int main() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(18); int n; cin >> n; cin >> x >> y; for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y; long double mini = 1e18, maxi = -1; for (int i = 0; i < n; i++) { long double b = getBest(p[i], p[(i + 1) % n]); mini = min(mini, b); long double far = getDist(p[i]); maxi = max(maxi, far); } cout << PI * (maxi - mini) << endl; }
#include <bits/stdc++.h> using namespace std; struct node { double x; double y; double dist; } input[100010]; const double PI = acos(-1.0); double get_dist(double x1, double y1, double x2, double y2) { double temp = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); return sqrt((double)temp); } double get_angle(double x1, double y1, double x2, double y2) { double temp1 = (x1 * x2 + y1 * y2); double temp2 = sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)); return temp1 / temp2; } double get_dist(double x1, double y1, double x2, double y2, double x3, double y3) { double a = y3 - y2; double b = x2 - x3; double c = x3 * y2 - x2 * y3; double dist = (double)abs(a * x1 + b * y1 + c) / sqrt((double)a * a + (double)b * b); double angle1 = get_angle(x3 - x2, y3 - y2, x1 - x2, y1 - y2); double angle2 = get_angle(x2 - x3, y2 - y3, x1 - x3, y1 - y3); if (angle1 <= 0 || angle2 <= 0) return -1; else return dist; } bool cmp(node n1, node n2) { if (n1.dist < n2.dist) return true; else return false; } vector<double> dists; int main() { int i, j, n; double x, y; while (scanf("%d%lf%lf", &n, &x, &y) != EOF) { dists.clear(); for (i = 0; i < n; i++) { scanf("%lf%lf", &input[i].x, &input[i].y); input[i].dist = get_dist(x, y, input[i].x, input[i].y); dists.push_back(input[i].dist); } for (i = 0; i < n; i++) { int cur = i, next = (i + 1) % n; double temp = get_dist(x, y, input[cur].x, input[cur].y, input[next].x, input[next].y); if (temp >= 0) dists.push_back(temp); } sort(dists.begin(), dists.end()); int tot = dists.size(); printf("%.15lf\n", PI * (double)(dists[tot - 1] * dists[tot - 1] - dists[0] * dists[0])); } return 0; }
#include <bits/stdc++.h> using namespace std; struct p { double x, y; }; int main() { int n; p P; double pi = 3.14159265358979323846; cin >> n >> P.x >> P.y; vector<p> ps(n); for (int i = 0; i < n; i++) cin >> ps[i].x >> ps[i].y; double max_d = -1, min_d; double dist; p p1, p2, p3; double d1, d2, d3, c12, c13, c23; for (int i = 0; i < n; i++) { p1 = ps[i % n]; p2 = ps[(i + 1) % n]; p3 = ps[(i + 2) % n]; d1 = sqrt((p1.x - P.x) * (p1.x - P.x) + (p1.y - P.y) * (p1.y - P.y)); d2 = sqrt((p2.x - P.x) * (p2.x - P.x) + (p2.y - P.y) * (p2.y - P.y)); d3 = sqrt((p3.x - P.x) * (p3.x - P.x) + (p3.y - P.y) * (p3.y - P.y)); min_d = min(d1, min(d2, d3)); c12 = ((p2.x - p1.x) * (P.x - p1.x) + (p2.y - p1.y) * (P.y - p1.y)) / ((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y)); c13 = ((p3.x - p1.x) * (P.x - p1.x) + (p3.y - p1.y) * (P.y - p1.y)) / ((p3.x - p1.x) * (p3.x - p1.x) + (p3.y - p1.y) * (p3.y - p1.y)); c23 = ((p3.x - p2.x) * (P.x - p2.x) + (p3.y - p2.y) * (P.y - p2.y)) / ((p3.x - p2.x) * (p3.x - p2.x) + (p3.y - p2.y) * (p3.y - p2.y)); if (c12 < 1.0 && c12 > 0.0) min_d = min(min_d, sqrt(d1 * d1 - c12 * c12 * ((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y)))); if (c13 < 1.0 && c13 > 0.0) min_d = min(min_d, sqrt(d1 * d1 - c13 * c13 * ((p3.x - p1.x) * (p3.x - p1.x) + (p3.y - p1.y) * (p3.y - p1.y)))); if (c23 < 1.0 && c23 > 0.0) min_d = min(min_d, sqrt(d2 * d2 - c23 * c23 * ((p3.x - p2.x) * (p3.x - p2.x) + (p3.y - p2.y) * (p3.y - p2.y)))); max_d = max( max_d, sqrt((p1.x - P.x) * (p1.x - P.x) + (p1.y - P.y) * (p1.y - P.y))); } double area = pi * max_d * max_d - pi * min_d * min_d; cout.precision(8); cout << fixed << area; }
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-8; namespace std { bool operator<(const complex<double> &a, const complex<double> &b) { return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b); } } // namespace std double cross(const complex<double> &a, const complex<double> &b) { return imag(conj(a) * b); } double dot(const complex<double> &a, const complex<double> &b) { return real(conj(a) * b); } struct L : public vector<complex<double> > { L(const complex<double> &a, const complex<double> &b) { push_back(a); push_back(b); } }; bool intersectSP(const L &s, const complex<double> &p) { return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < EPS; } complex<double> projection(const L &l, const complex<double> &p) { double t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]); return l[0] + t * (l[0] - l[1]); } double distanceSP(const L &s, const complex<double> &p) { const complex<double> r = projection(s, p); if (intersectSP(s, r)) return abs(r - p); return min(abs(s[0] - p), abs(s[1] - p)); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; double px, py; cin >> n >> px >> py; complex<double> p = {px, py}; vector<complex<double> > qs(n); for (int i = 0; (i) < (n); ++(i)) { double qx, qy; cin >> qx >> qy; qs[i] = {qx, qy}; } double a = INFINITY, b = 0; for (int i = 0; (i) < (n); ++(i)) { int j = (i + 1) % n; b = max(b, abs(qs[i] - p)); a = min(a, abs(qs[i] - p)); a = min(a, distanceSP(L(qs[i], qs[j]), p)); } printf("%.16lf\n", double(3.14159265358979323846 * (b * b - a * a))); return 0; }
#include <bits/stdc++.h> using namespace std; int n; double a, b, c[100005], d[100005]; double e, f; double r(double p, double q) { return p * p + q * q; } int main() { scanf("%d %lf %lf", &n, &a, &b); for (int i = (1); i <= (n); i++) scanf("%lf %lf", &c[i], &d[i]), c[i] -= a, d[i] -= b; c[n + 1] = c[1]; d[n + 1] = d[1]; e = f = r(c[1], d[1]); for (int i = (2); i <= (n); i++) { e = min(e, r(c[i], d[i])); f = max(f, r(c[i], d[i])); } for (int i = (1); i <= (n); i++) { if (c[i] * (c[i] - c[i + 1]) + d[i] * (d[i] - d[i + 1]) < 0) continue; if (c[i + 1] * (c[i + 1] - c[i]) + d[i + 1] * (d[i + 1] - d[i]) < 0) continue; e = min(e, r(0, abs(c[i] * d[i + 1] - d[i] * c[i + 1]) / sqrt(r(c[i] - c[i + 1], d[i] - d[i + 1])))); } printf("%.10lf\n", 3.14159265358979 * (f - e)); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 10; struct point { long long x, y; }; point p[MAXN]; int n; point pt; long double distanc(point p1, point p2) { return sqrt((p1.x - p2.x + 0.0) * (p1.x - p2.x + 0.0) + (p1.y - p2.y + 0.0) * (p1.y - p2.y + 0.0)); } int main() { cin >> n >> pt.x >> pt.y; for (int i = 0; i < n; ++i) cin >> p[i].x >> p[i].y; long double dist1 = 1000000000000000000LL; long double dist2 = 0; int mn_idx = 0; int mx_idx = 0; for (int i = 0; i < n; ++i) { if (dist1 > distanc(p[i], pt)) { dist1 = distanc(p[i], pt); mn_idx = i; } if (dist2 < distanc(p[i], pt)) { dist2 = distanc(p[i], pt); mx_idx = i; } } long double ans = dist2 * dist2 - dist1 * dist1; long double aans = ans * acos(-1.0); for (int i = 0; i < n; ++i) { int ii = (i + 1) % n; long double a = distanc(p[i], p[ii]); long double b = distanc(p[i], pt); long double c = distanc(p[ii], pt); if (b * b > a * a + c * c) continue; if (c * c > b * b + a * a) continue; long double p = (a + b + c) / 2; long double h = 2 * sqrt(p * (p - a) * (p - b) * (p - c)) / a; if (dist1 > h) dist1 = h; if (dist2 < h) dist2 = h; } ans = dist2 * dist2 - dist1 * dist1; aans = ans * acos(-1.0); cout << setprecision(15); fixed(cout); cout << aans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1E5 + 10; int n; int xp, yp; int x[MAXN], y[MAXN]; double sqr(double x) { return x * x; } long long crossProduct(int x1, int y1, int x2, int y2) { return x1 * (long long)y2 - x2 * (long long)y1; } int side(int x1, int y1, int x2, int y2) { long long res = crossProduct(x1, y1, x2, y2); return res > 0 ? 1 : res == 0 ? 0 : -1; } int main() { scanf("%d%d%d", &n, &xp, &yp); for (int i = 0; i < n; ++i) { scanf("%d%d", &x[i], &y[i]); x[i] -= xp; y[i] -= yp; } x[n] = x[0], y[n] = y[0]; double r1 = 1E8, r2 = 0.0; for (int i = 0; i < n; ++i) { double d = sqrt(sqr(x[i]) + sqr(y[i])); r1 = min(r1, d); r2 = max(r2, d); int x1 = y[i] - y[i + 1], y1 = x[i + 1] - x[i]; if (side(x1, y1, x[i], y[i]) * side(x1, y1, x[i + 1], y[i + 1]) <= 0) r1 = min(r1, fabs(crossProduct(x[i], y[i], x[i + 1], y[i + 1]) / sqrt(sqr(x1) + sqr(y1)))); } double ans = M_PI * (sqr(r2) - sqr(r1)); printf("%.12lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0.0); double p[2], c[2], pr[2]; int d[2]; long long revc[2]; int main() { int n, m, i, j; double dist, mn = -1, mx = -1; scanf("%d", &n); scanf("%d", &d[0]); scanf("%d", &d[1]); p[0] = (double)d[0]; p[1] = (double)d[1]; for (i = 0; i <= n; i++) { if (i < n) { scanf("%d", &d[0]); scanf("%d", &d[1]); c[0] = (double)d[0]; c[1] = (double)d[1]; } else { c[0] = revc[0]; c[1] = revc[1]; } dist = (c[0] - p[0]) * (c[0] - p[0]) + (c[1] - p[1]) * (c[1] - p[1]); if (i == 0) { mn = dist; mx = dist; revc[0] = c[0]; revc[1] = c[1]; pr[0] = c[0]; pr[1] = c[1]; continue; } else { mn = min(dist, mn); mx = max(dist, mx); } double x1, y1, a, b, cc, d, m; a = c[1] - pr[1]; b = pr[0] - c[0]; cc = -a * pr[0] - b * pr[1]; m = sqrt(a * a + b * b); a /= m; b /= m; cc /= m; d = p[0] * a + p[1] * b + cc; x1 = p[0] - (double)2.0 * a * d; y1 = p[1] - (double)2.0 * b * d; x1 = (x1 + p[0]) / (double)2.0; y1 = (y1 + p[1]) / (double)2.0; if (x1 >= min(c[0], pr[0]) && x1 <= max(c[0], pr[0]) && y1 >= min(c[1], pr[1]) && y1 <= max(c[1], pr[1])) { d = d * d; mn = min(d, mn); } pr[0] = c[0]; pr[1] = c[1]; } double ans = mx - mn; ans *= pi; printf("%.8lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 7; const long double Inf = 1e19 + 9; const long double pi = 3.1415926535897932384626433832795028841971693993751; struct point { long double x, y; }; int n; point p, P[Maxn]; long double operator^(point a, point b) { long double d = (a.x - b.x); long double D = (a.y - b.y); long double ret = d * d + D * D; return sqrt(ret); } long double operator%(point a, point b) { long double d = (a.y - b.y); long double D = (a.x - b.x); if (D != 0) return d / D; return -Inf; } point dis(long double a, long double b, long double A, long double B) { point ret; long double c = (A - a); long double C = (B - b); ret.x = C / c; ret.y = b + ((-a) * ret.x); return ret; } int main() { long double ans1 = 0, ans2 = Inf; cin >> n >> p.x >> p.y; for (int i = 0; i < n; i++) { cin >> P[i].x >> P[i].y; ans1 = max(ans1, P[i] ^ p); ans2 = min(ans2, P[i] ^ p); } for (int i = 0; i < n; i++) { int l = (i - 1 + n) % n; long double a = P[i] % P[l]; if (a && a != -Inf) { long double b = P[i].y - (a * P[i].x); long double A = (-1 / a); long double B = p.y - (A * p.x); point tmp = dis(-A, B, -a, b); if (tmp.x < min(P[l].x, P[i].x) || tmp.x > max(P[i].x, P[l].x)) continue; if (tmp.y < min(P[l].y, P[i].y) || tmp.y > max(P[i].y, P[l].y)) continue; ans2 = min(ans2, tmp ^ p); } else if (!a && p.x >= min(P[i].x, P[l].x) && p.x <= max(P[i].x, P[l].x)) ans2 = min(ans2, abs(p.y - P[i].y)); else if (a == -Inf && p.y >= min(P[i].y, P[l].y) && p.y <= max(P[i].y, P[l].y)) ans2 = min(ans2, abs(p.x - P[i].x)); } long double c = ans1 * ans1; long double C = ans2 * ans2; cout << fixed << setprecision(18) << (c - C) * pi << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; const long double INF = 1e18; const long double PI = acos(-1.0); int n; pair<long long, long long> o, origin, p[N]; long long r_1 = 0; long double r_2 = INF; long long sqDist(pair<long long, long long> a, pair<long long, long long> b) { return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second); } bool isObtuse(pair<long long, long long> a, pair<long long, long long> b, pair<long long, long long> c) { long long ab = sqDist(a, b), bc = sqDist(b, c), ca = sqDist(c, a); return ab + bc <= ca; } long double minDist(pair<long long, long long> a, pair<long long, long long> b) { long double diff_x = b.first - a.first, diff_y = b.second - a.second; if (diff_x == 0 and diff_y == 0) { diff_x = a.first; diff_y = a.second; return diff_x * diff_x + diff_y * diff_y; } long double t = (-a.first * diff_x - a.second * diff_y) / (1.0 * diff_x * diff_x + 1.0 * diff_y * diff_y); if (t < 0) { diff_x = a.first; diff_y = a.second; } else if (t > 1) { diff_x = b.first; diff_y = b.second; } else { diff_x = a.first + t * diff_x; diff_y = a.second + t * diff_y; } return diff_x * diff_x + diff_y * diff_y; } int main() { origin = pair<long long, long long>(0, 0); scanf("%d %lld %lld", &n, &o.first, &o.second); for (int i = 0; i < n; ++i) { scanf("%lld %lld", &p[i].first, &p[i].second); p[i].first -= o.first, p[i].second -= o.second; r_1 = max(r_1, sqDist(p[i], origin)); r_2 = min(r_2, (long double)sqDist(p[i], origin)); } p[n] = p[0]; for (int i = 0; i < n; ++i) { r_2 = min(r_2, minDist(p[i], p[i + 1])); } long double ans = max((long double)0.0, PI * (r_1 - r_2)); printf("%0.16f\n", (double)ans); return 0; }
#include <bits/stdc++.h> using namespace std; int n; pair<double, double> ori; pair<double, double> a[100007]; double dist(pair<double, double> p1, pair<double, double> p2) { return (p1.first - p2.first) * (p1.first - p2.first) + (p1.second - p2.second) * (p1.second - p2.second); } double det(pair<double, double> p1, pair<double, double> p2, pair<double, double> p3) { double ret = p1.first * p2.second + p1.second * p3.first + p2.first * p3.second; ret -= p3.first * p2.second + p3.second * p1.first + p2.first * p1.second; return ret; } int dot(pair<double, double> p1, pair<double, double> p2, pair<double, double> p3) { double aux = (p1.first - p2.first) * (p3.first - p2.first) + (p1.second - p2.second) * (p3.second - p2.second); if (aux < -0.00000001) { return -1; } if (aux > 0.00000001) { return 1; } return 0; } void input() { scanf("%d%lf%lf", &n, &ori.first, &ori.second); for (int i = 1; i <= n; ++i) { scanf("%lf%lf", &a[i].first, &a[i].second); } } void solve() { double mn, mx; mn = mx = -1; for (int i = 1; i <= n; ++i) { double sr = dist(a[i], ori); if (i == 1) { mn = mx = sr; } mn = min(mn, sr); mx = max(mx, sr); int nxt = i + 1; if (i == n) { nxt = 1; } if (dot(ori, a[i], a[nxt]) < 0) { continue; } if (dot(ori, a[nxt], a[i]) < 0) { continue; } double aux = det(a[i], a[nxt], ori); if (aux < 0) { aux = -aux; } aux /= sqrt(dist(a[i], a[nxt])); aux = (aux * aux); mn = min(mn, aux); } printf("%.12lf\n", acos(-1) * (mx - mn)); } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); int t; t = 1; while (t--) { input(); solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; double pi = asin(1) * 2; struct Point { double x; double y; }; double distance(Point p1, Point p2) { double lenth = (p1.x - p2.x) * (p1.x - p2.x) * 1.0 + (p1.y - p2.y) * (p1.y - p2.y) * 1.0; return lenth; } double pointToLine(Point o, Point p1, Point p2) { double a = (p2.x - p1.x) * (o.x - p1.x) + (p2.y - p1.y) * (o.y - p1.y); if (a < 0.0000001) return distance(o, p1); double b = (p1.x - p2.x) * (o.x - p2.x) + (p1.y - p2.y) * (o.y - p2.y); if (b < 0.0000001) return distance(o, p2); double op1 = distance(o, p1); double p1p2 = distance(p1, p2); double x = a / (sqrt(p1p2) * sqrt(op1)); double ans = sqrt(op1) * sqrt((1 - x * x)); return ans * ans; } int main() { int i, j, k, l, n, m; Point o, a[100111]; double maxlen = 0, minlen = 0, len; cin >> n >> o.x >> o.y; for (i = 0; i < n; i++) { cin >> a[i].x; cin >> a[i].y; } for (i = 0; i < n; i++) { len = pointToLine(o, a[i], a[(i + 1) % n]); if (minlen == 0) minlen = len; minlen = minlen < len ? minlen : len; maxlen = maxlen > len ? maxlen : len; } for (i = 0; i < n; i++) { len = distance(o, a[i]); maxlen = maxlen > len ? maxlen : len; minlen = minlen > len ? len : minlen; } double ans = (maxlen - minlen) * pi; printf("%.10lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); int n; pair<double, double> data[100010], P; double dis(pair<double, double> v1, pair<double, double> v2) { return ((v1.first - v2.first) * (v1.first - v2.first)) + ((v1.second - v2.second) * (v1.second - v2.second)); } double getDis(pair<double, double> v1, pair<double, double> v2, pair<double, double> o) { double angle1 = (o.first - v1.first) * (v2.first - v1.first) + (o.second - v1.second) * (v2.second - v1.second); double angle2 = (o.first - v2.first) * (v1.first - v2.first) + (o.second - v2.second) * (v1.second - v2.second); if (angle1 < 1e-8 || angle2 < 1e-8) return min(dis(v1, o), dis(v2, o)); double area = (v1.first - o.first) * (v2.second - o.second) - (v1.second - o.second) * (v2.first - o.first); return area * area / dis(v1, v2); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> P.first >> P.second; for (int i = 0; i < (n); i++) cin >> data[i].first >> data[i].second; double ma = 0, mi = 1e100; for (int i = 0; i < (n); i++) { ma = max(ma, dis(data[i], P)); mi = min(mi, getDis(data[i], data[(i + 1) % n], P)); } double ans; ans = (ma - mi) * pi; printf("%.20lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxN = 15e+5; const double Pi = acos(-1); const double EPS = 1e-9; struct Pnt { double x, y; }; struct Line { double a, b, c; Line() {} Line(Pnt p1, Pnt p2) { if (p1.x == p2.x) { a = 1; b = 0; } else { a = (p1.y - p2.y) / (p2.x - p1.x); b = 1; } c = -(a * p1.x + b * p1.y); } }; int N; Pnt P0, P[maxN]; double distP(Pnt a, Pnt b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } bool isEqual(double a, double b) { return fabs(a - b) < EPS; } bool isLessEqual(double a, double b) { return b - a >= -EPS; } Pnt intersectPoint(Line L1, Line L2) { Pnt p; p.x = (L1.b * L2.c - L2.b * L1.c) / (L1.a * L2.b - L2.a * L1.b); if (isEqual(L1.b, 0)) p.y = -(L2.a * p.x + L2.c); else p.y = -(L1.a * p.x + L1.c); return p; } Line perpendicularLine(Line l, Pnt p) { Line pL; pL.a = -l.b; pL.b = l.a; pL.c = -(pL.a * p.x + pL.b * p.y); return pL; } bool isIn(double p, double a, double b) { if (a > b) swap(a, b); return (isLessEqual(a, p) && isLessEqual(p, b)); } bool inSeg(Pnt p, Pnt a, Pnt b) { return (isIn(p.x, a.x, b.x) && isIn(p.y, a.y, b.y)); } double minDist(Pnt p, Pnt a, Pnt b) { Line l(a, b); Line pl = perpendicularLine(l, p); Pnt h = intersectPoint(l, pl); if (inSeg(h, a, b)) return distP(h, p); return min(distP(p, a), distP(p, b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> N >> P0.x >> P0.y; double R = 0.0, r = 1e9; for (int i = 1; i <= N; ++i) { cin >> P[i].x >> P[i].y; R = max(R, distP(P0, P[i])); } P[N + 1] = P[1]; for (int i = 1; i <= N; ++i) { r = min(r, minDist(P0, P[i], P[(i + 1)])); } long double res = Pi * (R * R - r * r); cout << fixed << setprecision(8) << res; }
#include <bits/stdc++.h> using namespace std; double shortestDisSq(double x1, double y1, double x2, double y2, double x, double y) { double magSq = pow(abs(x2 - x1), 2) + pow(abs(y2 - y1), 2); double proj = ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1)) / magSq; if (proj > 1) proj = 1; if (proj < 0) proj = 0; return pow(abs((x1 + proj * (x2 - x1)) - x), 2) + pow(abs((y1 + proj * (y2 - y1)) - y), 2); } int main() { int n; double x, y; cin >> n >> x >> y; double p, q; double op, oq, ip, iq; const double PI = 3.141592653589793238463; double dis; double R2 = 0; double r2 = 100000000000000; for (int i = 0; i < n; i++) { cin >> p >> q; if (i == 0) { ip = p; iq = q; } if (i > 0) r2 = min(r2, shortestDisSq(p, q, op, oq, x, y)); if (i == n - 1) r2 = min(r2, shortestDisSq(ip, iq, p, q, x, y)); op = p; oq = q; dis = pow(abs(x - p), 2) + pow(abs(y - q), 2); R2 = max(R2, dis); } double res = PI * (R2 - r2); printf("%.8lf\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1E6 + 10; const double pi = acos(-1); pair<int, int> p; pair<int, int> a[MAXN]; int n; long double R = 0, r = 0; long double tmp; inline int Readint() { int ret = 0; int f = 1; char ch; do { ch = getchar(); if (ch == '-') f *= -1; } while (ch >= 0 && (ch < '0' || ch > '9')); while ('0' <= ch && ch <= '9') { ret = ret * 10 + ch - '0'; ch = getchar(); } return ret * f; } void open() { freopen("A.in", "r", stdin); freopen("A.out", "w", stdout); } void close() { fclose(stdin); fclose(stdout); } inline long double cnt(const pair<int, int> &a, const pair<int, int> &b) { return 1.0L * (a.first - b.first) * (a.first - b.first) + 1.0L * (a.second - b.second) * (a.second - b.second); } inline long double dis(const pair<int, int> &a, const pair<int, int> &b) { return sqrt(cnt(a, b)); } inline long double cross(const pair<int, int> &o, const pair<int, int> &a, const pair<int, int> &b) { return 1.0L * (a.first - o.first) * (b.second - o.second) - 1.0L * (b.first - o.first) * (a.second - o.second); } inline long double linedis(const pair<int, int> &q, const pair<int, int> &p1, const pair<int, int> &p2) { return fabs(cross(q, p1, p2) / dis(p1, p2)); } inline long double get(const pair<int, int> &p1, const pair<int, int> &p2, const pair<int, int> &q) { pair<int, int> tmp = q; tmp.first += p1.second - p2.second; tmp.second += p2.first - p1.first; if (cross(p1, q, tmp) * cross(p2, q, tmp) >= 0) return min(dis(q, p1), dis(q, p2)); else return linedis(q, p1, p2); } inline long double sqr(long double a) { return a * a; } void init() { n = Readint(); p.first = Readint(), p.second = Readint(); R = 0; r = 1e18; for (int i = 1, _END_ = n; i <= _END_; i++) { a[i].first = Readint(), a[i].second = Readint(); tmp = cnt(a[i], p); R = max(R, tmp); r = min(r, tmp); if (i > 1) tmp = sqr(get(a[i - 1], a[i], p)); R = max(R, tmp); r = min(r, tmp); } tmp = sqr(get(a[1], a[n], p)); R = max(R, tmp); r = min(r, tmp); cout << setprecision(20) << (R - r) * pi << endl; } int main() { int _ = 0; init(); close(); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); struct node { double x, y; } a[100005], b; double fun(node a) { return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y)); } double fun(node a, node b) { return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y)); } int main() { int i, n; while (~scanf("%d%lf%lf", &n, &b.x, &b.y)) { for (i = 0; i < n; ++i) { scanf("%lf%lf", &a[i].x, &a[i].y); } a[n].x = a[0].x; a[n].y = a[0].y; double r_min = 1e18, r_max = 0; double t_r1, t_r2; for (i = 0; i < n; ++i) { t_r1 = fun(a[i]); t_r2 = fun(a[i + 1]); r_max = max(r_max, t_r1); r_max = max(r_max, t_r2); r_min = min(r_min, t_r1); r_min = min(r_min, t_r2); double t = fun(a[i], a[i + 1]); if (t_r1 * t_r1 + t * t < t_r2 * t_r2) ; else if (t_r2 * t_r2 + t * t < t_r1 * t_r1) ; else { double p = (t + t_r1 + t_r2) / 2; double s = sqrt(p * (p - t) * (p - t_r1) * (p - t_r2)); double r = 2 * s / t; r_min = min(r_min, r); } } printf("%.12f\n", pi * (r_max * r_max - r_min * r_min)); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; double xx[maxn], yy[maxn]; double dist(double x, double y, double x1, double y1, double x2, double y2) { if ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1) <= 0) return sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); if ((x - x2) * (x1 - x2) + (y - y2) * (y1 - y2) <= 0) return sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y)); return abs(((x - x1) * (y2 - y1) - (x2 - x1) * (y - y1)) / sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1))); } int main() { double maxx = 0, minn = 2000000; int n; double x, y; scanf("%d%lf%lf", &n, &x, &y); for (int i = 1; i <= n; i++) { scanf("%lf%lf", &xx[i], &yy[i]); double ans = sqrt((xx[i] - x) * (xx[i] - x) + (yy[i] - y) * (yy[i] - y)); maxx = max(maxx, ans); if (i == 1) continue; double anss = dist(x, y, xx[i - 1], yy[i - 1], xx[i], yy[i]); minn = min(minn, anss); } minn = min(minn, dist(x, y, xx[n], yy[n], xx[1], yy[1])); double answer = acos(-1) * (maxx * maxx - minn * minn); printf("%lf\n", answer); }
#include <bits/stdc++.h> double sq(double x) { return x * x; } int dbg = 1; using namespace std; pair<int, int> arr[100005]; double shortest(int x, int y, int a, int b) { double x1 = x, y1 = y, x2 = a, y2 = b; if (x1 == x2) if (y1 * y2 <= 0) return sq(x1); else return sq(min(y1, y2)) + sq(x1); double m = (y2 - y1) / (x2 - x1); double c = y1 - m * x1; if ((m * y1 + x1) * (m * y2 + x2) < 0) { double x, y; x = -1 * (m * c) / (1 + sq(m)); y = c / (1 + sq(m)); return sq(x) + sq(y); } return min(sq(x1) + sq(y1), sq(x2) + sq(y2)); } int main() { int n, x, y; double mini = 1e15, maxi = 0, pi = 3.1415926535897932; cin >> n >> x >> y; for (int i = 0; i < n; i++) { scanf("%d %d", &arr[i].first, &arr[i].second); ; arr[i].first -= x; arr[i].second -= y; } for (int i = 0; i < n - 1; i++) { mini = min(mini, shortest(arr[i].first, arr[i].second, arr[i + 1].first, arr[i + 1].second)); maxi = max(maxi, sq(arr[i].first) + sq(arr[i].second)); } maxi = max(maxi, sq(arr[n - 1].first) + sq(arr[n - 1].second)); mini = min(mini, shortest(arr[0].first, arr[0].second, arr[n - 1].first, arr[n - 1].second)); printf("%.9lf\n", pi * (maxi - mini)); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); const double EPS = 1e-10; int dcmp(double x) { if (fabs(x) < EPS) return 0; else return x < 0 ? -1 : 1; } struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} Point operator-(const Point &r) const { return Point(x - r.x, y - r.y); } bool operator==(const Point &r) const { return dcmp(x - r.x) == 0 && dcmp(y - r.y) == 0; } }; double cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } double dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } double length(Point A) { return sqrt(dot(A, A)); } Point read_point(void) { double x, y; scanf("%lf%lf", &x, &y); return Point(x, y); } Point o; double squ(double x) { return x * x; } bool cmp(Point a, Point b) { double la = squ(a.x - o.x) + squ(a.y - o.y); double lb = squ(b.x - o.x) + squ(b.y - o.y); return dcmp(la - lb) < 0; } double point_to_seg(Point p, Point a, Point b) { if (a == b) return length(p - a); Point 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 p[N]; int main(void) { int n; scanf("%d", &n); o = read_point(); double mn = 1e16; bool flag = true; for (int i = 0; i < n; ++i) { p[i] = read_point(); if (i > 0) { double dis = point_to_seg(o, p[i], p[i - 1]); if (dcmp(dis - mn) < 0) mn = dis; } } double dis = point_to_seg(o, p[0], p[n - 1]); if (dcmp(dis - mn) < 0) mn = dis; sort(p, p + n, cmp); double r2 = squ(p[0].x - o.x) + squ(p[0].y - o.y); if (dcmp(r2 - squ(mn)) > 0) r2 = squ(mn); double R2 = squ(p[n - 1].x - o.x) + squ(p[n - 1].y - o.y); if (!flag) printf("%.16f\n", PI * R2); else printf("%.16f\n", PI * (R2 - r2)); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } int inf = 0x3f3f3f3f; long long infl = 0x3f3f3f3f3f3f3f3fLL; long double infd = 1.0 / 0.0; const long long MOD = 1e9 + 7; const long double pi = 2 * acos(0.0); long double eps = 1e-7; bool same_side(pair<long double, long double> A, pair<long double, long double> B, pair<long double, long double> C, long double m) { if (fabs(m) < eps) { if ((A.second - C.second) * (B.second - C.second) < 0) return 1; return 0; } if (fabs(1 / m) < eps) { if ((A.first - C.first) * (B.first - C.first) < 0) return 1; return 0; } long double gx = A.second - m * A.first + m * C.first - C.second; long double gy = B.second - m * B.first + m * C.first - C.second; if (gx * gy < 0) return 1; return 0; } long double dist(pair<long double, long double> A, pair<long double, long double> B) { long double res = (long double)sqrt((A.first - B.first) * (A.first - B.first) + (A.second - B.second) * (A.second - B.second)); return res; } long double ppd(pair<long double, long double> A, pair<long double, long double> B, pair<long double, long double> C) { long double le = dist(A, C); long double ri = dist(B, C); long double m = (B.second - A.second) / (B.first - A.first); long double len = (long double)sqrt((long double)1 + m * m); long double num = C.second - m * C.first + m * A.first - A.second; long double md = fabs(num / len); if (fabs(B.first - A.first) < eps) md = fabs(C.first - A.first); long double m2 = -1 / m; bool is_same = same_side(A, B, C, m2); if (is_same) return md; return infd; } int main() { ios::sync_with_stdio(0); cin.tie(0); ; int n, p, q; cin >> n >> p >> q; long double as = pi; long double mx = -infd, mn = infd; vector<pair<int, int>> pts; while (n--) { int x, y; cin >> x >> y; pts.push_back({x, y}); long double gg = dist({x, y}, {p, q}); if (gg > mx) mx = gg; if (gg < mn) mn = gg; } n = (int)pts.size(); for (int i = 0; i < n; i++) { pair<int, int> A = pts[i]; pair<int, int> B = pts[(i + 1) % n]; long double gg = ppd(A, B, {p, q}); if (gg < mn) mn = gg; } as *= (long double)(mx * mx - mn * mn); cout << fixed << setprecision(18) << as; return 0; }
#include <bits/stdc++.h> using namespace std; long double INF = 1e18; const int N = 1e5 + 1; long double PI = 2 * acos(0); long double EPS = 1e-7; complex<long double> v[N]; long double dot(complex<long double> u, complex<long double> v) { return u.real() * v.real() + u.imag() * v.imag(); } void get_line(complex<long double> p1, complex<long double> p2, long double &a, long double &b, long double &c) { a = p2.imag() - p1.imag(); b = p1.real() - p2.real(); c = p1.imag() * p2.real() - p2.imag() * p1.real(); } complex<long double> intersect(long double a, long double b, long double c, long double e, long double f, long double g) { return complex<long double>(-(b * g - c * f) / (b * e - a * f), -(a * g - c * e) / (a * f - b * e)); } bool is_inside(complex<long double> p, complex<long double> l1, complex<long double> l2) { long double a, b, c, e, f, g, m; m = (l2.imag() - l1.imag()) / (l2.real() - l1.real()); m = -1 / m; get_line(l1, l2, a, b, c); get_line(p, p + (l2.imag() == l1.imag() ? complex<long double>(0, 1) : (l2.real() == l1.real() ? complex<long double>(1, 0) : complex<long double>(1, m))), e, f, g); complex<long double> p2 = intersect(a, b, c, e, f, g); long double d, d1, d2; d = sqrt(dot(l2 - l1, l2 - l1)); d1 = sqrt(dot(p2 - l1, p2 - l1)); d2 = sqrt(dot(p2 - l2, p2 - l2)); return abs(d1 + d2 - d) < EPS; } long double dist(long double x, long double y, complex<long double> l1, complex<long double> l2) { long double a, b, c; get_line(l1, l2, a, b, c); return (a * x + b * y + c) * (a * x + b * y + c) / (a * a + b * b); } int main() { ios::sync_with_stdio(0); int n; long double px, py; while (cin >> n >> px >> py) { complex<long double> p = complex<long double>(px, py); long double r, rr; r = INF; rr = 0; for (int i = 0; i < n; i++) { long double x, y; cin >> x >> y; v[i] = complex<long double>(x, y); long double d = (x * x - 2 * x * px + px * px + py * py - 2 * y * py + y * y); r = min(r, d); rr = max(rr, d); } v[n] = v[0]; for (int i = 0; i < n; i++) { long double d = dist(px, py, v[i], v[i + 1]); if (d < r && is_inside(p, v[i], v[i + 1])) r = d; } cout << setprecision(13) << fixed << PI * (rr - r) << "\n\n"; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const double PI = acos(-1.0); const double eps = 1e-9; struct Point { double x, y; } o, ps[maxn]; int n; double ans1, ans2; double dist(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } double cross(Point o, Point a, Point b) { return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y); } int main() { int i, j, x, y; Point tmp; scanf("%d%lf%lf", &n, &o.x, &o.y); for (i = 0; i < n; i++) scanf("%lf%lf", &ps[i].x, &ps[i].y); ps[n] = ps[0]; ans1 = 0; ans2 = 1e15; for (i = 0; i < n; i++) { ans1 = max(ans1, dist(o, ps[i])); ans2 = min(ans2, dist(o, ps[i])); } for (i = 0; i < n; i++) { tmp.x = o.x + ps[i].y - ps[i + 1].y; tmp.y = o.y + ps[i + 1].x - ps[i].x; if (cross(o, tmp, ps[i]) * cross(o, tmp, ps[i + 1]) < eps) { ans2 = min(ans2, fabs(cross(o, ps[i], ps[i + 1]) / dist(ps[i], ps[i + 1]))); } } printf("%.9f\n", PI * (ans1 * ans1 - ans2 * ans2)); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; struct Point { long long x, y; } p0; long long dis(Point a, Point b) { return (long long)(a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } double ptolin(Point p, Point a, Point b) { long long pa = dis(p, a); long long pb = dis(p, b); long long ab = dis(a, b); if (pb >= pa + ab) return min(pa, pb); else if (pa >= pb + ab) return min(pa, pb); else { Point v1, v2; v1.x = b.x - a.x; v1.y = b.y - a.y; v2.x = p.x - a.x; v2.y = p.y - a.y; double cross = v1.x * v2.y - v1.y * v2.x; if (cross < 0) cross *= -1; cross = cross * cross / dis(b, a); return cross; } } vector<Point> p; int main() { long long r = 0; int n; cin >> n >> p0.x >> p0.y; for (int i = 0; i < n; i++) { Point x; cin >> x.x >> x.y; p.push_back(x); long long tmp = dis(x, p0); r = max(r, tmp); } double l = 1e17; for (int i = 0; i < p.size(); i++) { int j = (i == p.size() - 1) ? 0 : i + 1; l = min(l, ptolin(p0, p[i], p[j])); } double ans = acos(-1) * (double)(r - l); printf("%.10f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; const int maxm = 310; const int mod = 1e9 + 7; const int inf = 1e9 + 7; const int dev = 100010; const double eps = 1e-6; const double EPS = eps; const double pi = acos(-1.0); int n, m; struct Point { int id; double x, y; Point() {} Point(double _x, double _y) { x = _x; y = _y; } Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); } double operator^(const Point &b) const { return x * b.y - y * b.x; } double operator*(const Point &b) const { return x * b.x + y * b.y; } } pp[maxn]; struct Line { Point a; Point b; Line() {} Line(Point _a, Point _b) { a = _a; b = _b; } } line[maxn]; Line ll[maxn]; struct Circle { double r; Point ctr; Circle() {} Circle(double _r, Point _a) { r = _r; ctr = _a; } }; double dist(Point a, Point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } double Xmult(Point a, Point b, Point c) { return ((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y)); } int sgn(double x) { if (fabs(x) < EPS) return 0; if (x < 0) return -1; else return 1; } bool judgelinecross(Line gg, Line ff) { int i, j; if (dist(gg.a, gg.b) < EPS) return false; else if (dist(ff.a, ff.b) < EPS) return false; double gx = Xmult(gg.a, gg.b, ff.a); double gy = Xmult(gg.a, gg.b, ff.b); if (gx * gy > EPS) return false; return true; } bool intersect(Line gg, Line ff) { return sgn(Xmult(ff.a, ff.b, gg.a)) * sgn(Xmult(ff.a, ff.b, gg.b)) == -1; } Point crossing(Line u, Line v) { double a1 = u.a.y - u.b.y; double b1 = u.b.x - u.a.x; double c1 = u.a.x * u.b.y - u.b.x * u.a.y; double a2 = v.a.y - v.b.y; double b2 = v.b.x - v.a.x; double c2 = v.a.x * v.b.y - v.b.x * v.a.y; double ansx = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1); double ansy = (a2 * c1 - a1 * c2) / (a1 * b2 - a2 * b1); return Point(ansx, ansy); } bool inter(Line l1, Line l2) { return max(l1.a.x, l1.b.x) >= min(l2.a.x, l2.b.x) && max(l2.a.x, l2.b.x) >= min(l1.a.x, l1.b.x) && max(l1.a.y, l1.b.y) >= min(l2.a.y, l2.b.y) && max(l2.a.y, l2.b.y) >= min(l1.a.y, l1.b.y) && sgn((l2.a - l1.a) ^ (l1.b - l1.a)) * sgn((l2.b - l1.a) ^ (l1.b - l1.a)) <= 0 && sgn((l1.a - l2.a) ^ (l2.b - l2.a)) * sgn((l1.b - l2.a) ^ (l2.b - l2.a)) <= 0; } Point NearestPointToLineSeg(Point P, Line L) { Point result; double t = ((P - L.a) * (L.b - L.a)) / ((L.b - L.a) * (L.b - L.a)); if (t >= 0 && t <= 1) { result.x = L.a.x + (L.b.x - L.a.x) * t; result.y = L.a.y + (L.b.y - L.a.y) * t; } else { if (dist(P, L.a) < dist(P, L.b)) result = L.a; else result = L.b; } return result; } double dist_Point_Line(Point P, Line L) { Point gg = NearestPointToLineSeg(P, L); return dist(P, gg); } int main() { int i, j; while (scanf("%d", &n) != EOF) { for (i = 0; i <= n; i++) { scanf("%lf%lf", &pp[i].x, &pp[i].y); } pp[n + 1] = pp[1]; double mi = 1e16, mx = 0; for (i = 1; i <= n; i++) { double temp1 = dist_Point_Line(pp[0], Line(pp[i], pp[i + 1])); double temp2 = dist(pp[0], pp[i]); mi = min(mi, temp1); mx = max(mx, temp2); } double ans = (mx * mx - mi * mi) * pi; printf("%.10f\n", ans); } }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); struct node { double a, b; } e[100010]; int n; double getl(node X, node Y) { double d1 = (X.a - Y.a) * (X.a - Y.a); double d2 = (X.b - Y.b) * (X.b - Y.b); return sqrt(d1 + d2); } double getlength(node A, node B, node C, double &temp) { double a = getl(A, C); double b = getl(B, C); double c = getl(A, B); temp = max(a, b); if (a * a >= b * b + c * c) return b; if (b * b >= a * a + c * c) return a; double pp = (a + b + c) / 2; double s = (pp - a) * (pp - b) * (pp - c) * pp; s = sqrt(s); double d = s * 2 / c; return d; } int main() { node t; int i, j; while (cin >> n) { cin >> t.a >> t.b; for (i = 0; i < n; i++) cin >> e[i].a >> e[i].b; double maxn = -(double)10000000; ; double minx = (double)10000000; ; double temp; for (i = 0; i < n; i++) { minx = min(minx, getlength(e[i], e[(i + 1) % n], t, temp)); maxn = max(maxn, temp); } double ans = PI * (maxn * maxn - minx * minx); printf("%.10lf\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double PI = acos(-1.0); const int MAXN = 1e5 + 9; int sgn(double x) { if (fabs(x) < eps) return 0; if (x < 0) return -1; else return 1; } struct POint { double x, y; POint() {} POint(double _x, double _y) { x = _x; y = _y; } POint operator-(const POint &b) const { return POint(x - b.x, y - b.y); } double operator^(const POint &b) const { return x * b.y - y * b.x; } double operator*(const POint &b) const { return x * b.x + y * b.y; } void transXY(double B) { double tx = x, ty = y; x = tx * cos(B) - ty * sin(B); y = tx * sin(B) + ty * cos(B); } }; struct LIne { POint s, e; LIne() {} LIne(POint _s, POint _e) { s = _s; e = _e; } pair<int, POint> operator&(const LIne &b) const { POint res = s; if (sgn((s - e) ^ (b.s - b.e)) == 0) { if (sgn((s - b.e) ^ (b.s - b.e)) == 0) return make_pair(0, res); else return make_pair(1, res); } double t = ((s - b.s) ^ (b.s - b.e)) / ((s - e) ^ (b.s - b.e)); res.x += (e.x - s.x) * t; res.y += (e.y - s.y) * t; return make_pair(2, res); } }; double dist(POint a, POint b) { return sqrt((a - b) * (a - b)); } bool inter(LIne l1, LIne l2) { return max(l1.s.x, l1.e.x) >= min(l2.s.x, l2.e.x) && max(l2.s.x, l2.e.x) >= min(l1.s.x, l1.e.x) && max(l1.s.y, l1.e.y) >= min(l2.s.y, l2.e.y) && max(l2.s.y, l2.e.y) >= min(l1.s.y, l1.e.y) && sgn((l2.s - l1.e) ^ (l1.s - l1.e)) * sgn((l2.e - l1.e) ^ (l1.s - l1.e)) <= 0 && sgn((l1.s - l2.e) ^ (l2.s - l2.e)) * sgn((l1.e - l2.e) ^ (l2.s - l2.e)) <= 0; } bool Seg_inter_line(LIne l1, LIne l2) { return sgn((l2.s - l1.e) ^ (l1.s - l1.e)) * sgn((l2.e - l1.e) ^ (l1.s - l1.e)) <= 0; } POint PointToLine(POint P, LIne L) { POint result; double t = ((P - L.s) * (L.e - L.s)) / ((L.e - L.s) * (L.e - L.s)); result.x = L.s.x + (L.e.x - L.s.x) * t; result.y = L.s.y + (L.e.y - L.s.y) * t; return result; } POint NearestPointToLineSeg(POint P, LIne L) { POint result; double t = ((P - L.s) * (L.e - L.s)) / ((L.e - L.s) * (L.e - L.s)); if (t >= 0 && t <= 1) { result.x = L.s.x + (L.e.x - L.s.x) * t; result.y = L.s.y + (L.e.y - L.s.y) * t; } else { if (dist(P, L.s) < dist(P, L.e)) result = L.s; else result = L.e; } return result; } double CalcArea(POint p[], int n) { double res = 0; for (int i = 0; i < n; i++) res += (p[i] ^ p[(i + 1) % n]) / 2; return fabs(res); } bool OnSeg(POint P, LIne L) { return sgn((L.s - P) ^ (L.e - P)) == 0 && sgn((P.x - L.s.x) * (P.x - L.e.x)) <= 0 && sgn((P.y - L.s.y) * (P.y - L.e.y)) <= 0; } int inConvexPoly(POint a, POint p[], int n) { for (int i = 0; i < n; i++) { if (sgn((p[i] - a) ^ (p[(i + 1) % n] - a)) < 0) return -1; else if (OnSeg(a, LIne(p[i], p[(i + 1) % n]))) return 0; } return 1; } int inPoly(POint p, POint poly[], int n) { int cnt; LIne ray, side; cnt = 0; ray.s = p; ray.e.y = p.y; ray.e.x = -100000000000.0; for (int i = 0; i < n; i++) { side.s = poly[i]; side.e = poly[(i + 1) % n]; if (OnSeg(p, side)) return 0; if (sgn(side.s.y - side.e.y) == 0) continue; if (OnSeg(side.s, ray)) { if (sgn(side.s.y - side.e.y) > 0) cnt++; } else if (OnSeg(side.e, ray)) { if (sgn(side.e.y - side.s.y) > 0) cnt++; } else if (inter(ray, side)) cnt++; } if (cnt % 2 == 1) return 1; else return -1; } bool isconvex(POint poly[], int n) { bool s[3]; memset(s, false, sizeof(s)); for (int i = 0; i < n; i++) { s[sgn((poly[(i + 1) % n] - poly[i]) ^ (poly[(i + 2) % n] - poly[i])) + 1] = true; if (s[0] && s[2]) return false; } return true; } POint lis[MAXN]; int Stack[MAXN], top; bool _cmp(POint p1, POint p2) { double tmp = (p1 - lis[0]) ^ (p2 - lis[0]); if (sgn(tmp) > 0) return true; else if (sgn(tmp) == 0 && sgn(dist(p1, lis[0]) - dist(p2, lis[0])) <= 0) return true; else return false; } void Graham(int n) { POint p0; int k = 0; p0 = lis[0]; for (int i = 1; i < n; i++) { if ((p0.y > lis[i].y) || (p0.y == lis[i].y && p0.x > lis[i].x)) { p0 = lis[i]; k = i; } } swap(lis[k], lis[0]); sort(lis + 1, lis + n, _cmp); if (n == 1) { top = 1; Stack[0] = 0; return; } if (n == 2) { top = 2; Stack[0] = 0; Stack[1] = 1; return; } Stack[0] = 0; Stack[1] = 1; top = 2; for (int i = 2; i < n; i++) { while (top > 1 && sgn((lis[Stack[top - 1]] - lis[Stack[top - 2]]) ^ (lis[i] - lis[Stack[top - 2]])) <= 0) top--; Stack[top++] = i; } } struct CIrcle { POint c; double r; CIrcle(POint c, double r) : c(c), r(r) {} CIrcle() {} CIrcle(double _x, double _y, double _r) { c.x = _x; c.y = _y; r = _r; } }; POint operator*(double a, POint p) { return POint(a * p.x, a * p.y); } POint operator+(POint a, POint b) { return POint(a.x + b.x, b.y + a.y); } POint operator*(POint a, double b) { return POint(a.x * b, a.y * b); } struct LINE { POint p, v; POint pointofline(double t) { return p + t * v; } }; int main() { int a, d, e, f; POint o, tmp; cin >> a >> o.x >> o.y; for (d = 0; d < a; d++) { cin >> lis[d].x >> lis[d].y; } double res = 1e9, res1 = 0.0; for (d = 0; d < a; d++) { e = d; f = (d + 1) % a; tmp = NearestPointToLineSeg(o, LIne(lis[e], lis[f])); res = min(res, dist(o, lis[e])); res = min(res, dist(o, tmp)); res1 = max(dist(o, lis[d]), res1); } cout << fixed << setprecision(9) << (res1 * res1 - res * res) * PI << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } double EPS = 0.0000001; int N; complex<double> P; complex<double> V[100010]; double dot(complex<double> a, complex<double> b) { return (a.real() * b.real() + a.imag() * b.imag()); } double cross(complex<double> a, complex<double> b) { return (a.real() * b.imag() - a.imag() * b.real()); } double distance_ls_p(complex<double> a, complex<double> b, complex<double> c) { if (dot(b - a, c - a) < EPS) return abs(c - a); if (dot(a - b, c - b) < EPS) return abs(c - b); return abs(cross(b - a, c - a)) / abs(b - a); } int main() { int x, y; cin >> N >> x >> y; P = {(double)x, (double)y}; double near = 1e13; double far = 0; for (int i = 0; i < (N); i++) { cin >> x >> y; V[i] = {(double)x, (double)y}; near = (near < abs(V[i] - P) ? near : abs(V[i] - P)); far = (far > abs(V[i] - P) ? far : abs(V[i] - P)); } for (int i = 0; i < (N); i++) { int j = (i + 1) % N; double d = distance_ls_p(V[i], V[j], P); amax(far, d); amin(near, d); } double a = (far * far - near * near) * 3.14159265358979; (void)printf("%.10f\n", a); return 0; }
#include <bits/stdc++.h> using namespace std; void fast_io() { cin.tie(0); ios::sync_with_stdio(false); } long long exp(long long a, long long b) { if (b == 0) return 1; else if (b & 1) return a * exp(a, b - 1); else { long long ans = exp(a, b / 2); return ans * ans; } } using namespace std; double INF = 1e100; double EPS = 1e-12; struct PT { double x, y; PT() {} PT(double x, double y) : x(x), y(y) {} PT(const PT &p) : x(p.x), y(p.y) {} PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); } PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); } PT operator*(double c) const { return PT(x * c, y * c); } PT operator/(double c) const { return PT(x / c, y / c); } }; double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; } double dist2(PT p, PT q) { return dot(p - q, p - q); } double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; } ostream &operator<<(ostream &os, const PT &p) { os << "(" << p.x << "," << p.y << ")"; } PT RotateCCW90(PT p) { return PT(-p.y, p.x); } PT RotateCW90(PT p) { return PT(p.y, -p.x); } PT RotateCCW(PT p, double t) { return PT(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t)); } PT ProjectPointLine(PT a, PT b, PT c) { return a + (b - a) * dot(c - a, b - a) / dot(b - a, b - a); } PT ProjectPointSegment(PT a, PT b, PT c) { double r = dot(b - a, b - a); if (fabs(r) < EPS) return a; r = dot(c - a, b - a) / r; if (r < 0) return a; if (r > 1) return b; return a + (b - a) * r; } double DistancePointSegment(PT a, PT b, PT c) { return dist2(c, ProjectPointSegment(a, b, c)); } int main() { long long n; scanf("%lld", &n); PT p; scanf("%lf", &p.x); scanf("%lf", &p.y); double ans = 0; double mn = 1e16; double mx = 0; PT prev; PT fst; for (long long i = 0; i <= n; i++) { PT temp; if (i != n) { scanf("%lf", &temp.x); scanf("%lf", &temp.y); } else temp = fst; if (i == 0) fst = temp; double dist = (temp.x - p.x) * (temp.x - p.x) + (temp.y - p.y) * (temp.y - p.y); if (dist < mn) mn = dist; if (dist > mx) mx = dist; if (i != 0) { double dist = DistancePointSegment(temp, prev, p); if (dist < mn) mn = dist; if (dist > mx) mx = dist; } prev = temp; } printf("%0.9lf\n", M_PI * (mx - mn)); return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point(double X = 0.0, double Y = 0.0) { x = X; y = Y; } Point operator+(const Point &A) const { return Point(A.x + x, A.y + y); } Point operator-(const Point &A) const { return Point(x - A.x, y - A.y); } double operator*(const Point &A) const { return x * A.x + y * A.y; } double operator^(const Point &A) const { return x * A.y - y * A.x; } bool operator==(const Point &A) const { return (x == A.x && y == A.y); } bool operator<(const Point &A) const { if (x == A.x) return y < A.y; return x < A.x; } }; double norma(const Point &A) { return sqrt(A * A); } double dist(const Point &A, const Point &B) { return norma(A - B); } bool f(Point P, Point A, Point B) { double a = dist(P, A); double b = dist(P, B); double c = dist(A, B); return (((a * a + c * c) >= b * b) && ((b * b + c * c) >= a * a)); } double dist_Point_to_Line(Point P, Point P0, Point P1) { double a = dist(P, P0); double b = dist(P, P1); double c = dist(P1, P0); double s = (a + b + c) / 2.0; return 2.0 * sqrt(s * (s - a) * (s - b) * (s - c)) / c; } int main() { int n; Point P, C; double a = 0x3f3f3f3f * 1.0, b = 0.0, x, ans; scanf("%d", &n); vector<Point> v(n); cin >> P.x >> P.y; for (int i = 0; i < n; i++) cin >> v[i].x >> v[i].y; for (int i = 0; i < n; i++) { x = dist(P, v[i]); a = min(a, x); b = max(b, x); if (f(P, v[i], v[(i + 1) % n])) { a = min(a, dist_Point_to_Line(P, v[i], v[(i + 1) % n])); } } ans = (b * b - a * a) * acos(-1.0); printf("%.8lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const double pi = acos(-1.0); int n; long long xx, yy; double maxx, minn; const double eps = 1e-10; struct Point { double x, y, dis; void read() { cin >> x >> y; dis = (x - xx) * (x - xx) + (y - yy) * (y - yy); maxx = max(maxx, dis); minn = min(dis, minn); } void make(double _x, double _y) { x = _x, y = _y; } Point(double x = 0, double y = 0) : x(x), y(y) {} } node[maxn], line[maxn], cir; typedef Point Vector; 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 p) { return Vector(A.x * p, A.y * p); } Vector operator/(Vector A, double p) { return Vector(A.x / p, A.y / p); } 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; } 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; } 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) { double L = Length(A); return Vector(-A.y / L, A.x / L); } Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) { Vector u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v * t; } double DistanceToLine(Point P, Point A, Point B) { Vector v1 = B - A, v2 = P - A; return fabs(Cross(v1, v2)) / Length(v1); } Point GetlLineProjection(Point P, Point A, Point B) { Vector v = B - A; return A + v * (Dot(v, P - A) / Dot(v, v)); } int main() { while (cin >> n >> xx >> yy) { maxx = 0; minn = 1e50; for (int i = 0; i < n; i++) node[i].read(); for (int i = 0; i < n; i++) line[i].make(node[i].x - node[(i + 1) % n].x, node[i].y - node[(i + 1) % n].y); cir.make(xx, yy); for (int i = 0; i < n; i++) { double now_dis = DistanceToLine(cir, node[i], node[(i + 1) % n]); Vector fa = Normal(line[i]); Point jiao = cir + fa * now_dis; if (((jiao.x >= node[i].x && jiao.x <= node[(i + 1) % n].x) || (jiao.x <= node[i].x && jiao.x >= node[(i + 1) % n].x)) && ((jiao.y >= node[i].y && jiao.y <= node[(i + 1) % n].y) || (jiao.y <= node[i].y && jiao.y >= node[(i + 1) % n].y))) { minn = min(minn, now_dis * now_dis); } } for (int i = 0; i < n; i++) { double now_dis = DistanceToLine(cir, node[i], node[(i + 1) % n]); line[i].x = -line[i].x, line[i].y = -line[i].y; Vector fa = Normal(line[i]); Point jiao = cir + fa * now_dis; if (((jiao.x >= node[i].x && jiao.x <= node[(i + 1) % n].x) || (jiao.x <= node[i].x && jiao.x >= node[(i + 1) % n].x)) && ((jiao.y >= node[i].y && jiao.y <= node[(i + 1) % n].y) || (jiao.y <= node[i].y && jiao.y >= node[(i + 1) % n].y))) { minn = min(minn, now_dis * now_dis); } } printf("%.18lf\n", (maxx - minn) * pi); } }
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; long long point[1000000 + 5][2]; long long p1, p2; double dis(long long a1, long long b1, long long a2, long long b2) { return sqrt((a1 - a2) * (a1 - a2) + (b1 - b2) * (b1 - b2)); } double disdis(int i, int j) { double a = dis(p1, p2, point[i][0], point[i][1]); if (a < 0.0001) return 0.0; double b = dis(p1, p2, point[j][0], point[j][1]); if (b < 0.0001) return 0.0; double c = dis(point[i][0], point[i][1], point[j][0], point[j][1]); if (c < 0.0001) return 0.0; if (a * a >= b * b + c * c) return b * b; if (b * b >= a * a + c * c) return a * a; double p = (a + b + c) / 2; double s = sqrt(p * (p - a) * (p - b) * (p - c)); return 4 * s * s / c / c; } int main() { int n; scanf("%d %I64d %I64d", &n, &p1, &p2); long long maxx = 0, a, b; double minn = 10000000000000; for (int i = 0; i < n; i++) { scanf("%I64d %I64d", &a, &b); point[i][0] = a; point[i][1] = b; maxx = max(maxx, (p1 - a) * (p1 - a) + (p2 - b) * (p2 - b)); } for (int i = 0; i < n; i++) minn = min(minn, disdis(i, (i + 1) % n)); printf("%.12lf\n", 3.1415926 * (maxx - minn)); return 0; }
#include <bits/stdc++.h> using namespace std; struct p { double x, y; } a[100005]; double x, y; int main() { int n; while (~scanf("%d%lf%lf", &n, &x, &y)) { double r = 1000000000, R = 0; for (int i = 1; i <= n; i++) { scanf("%lf%lf", &a[i].x, &a[i].y); r = min(r, sqrt((a[i].x - x) * (a[i].x - x) + (a[i].y - y) * (a[i].y - y))); R = max(R, sqrt((a[i].x - x) * (a[i].x - x) + (a[i].y - y) * (a[i].y - y))); } a[0].x = a[n].x, a[0].y = a[n].y; for (int i = 1; i <= n; i++) { if ((a[i - 1].x - a[i].x) * (x - a[i].x) + (a[i - 1].y - a[i].y) * (y - a[i].y) <= 0) continue; if ((a[i].x - a[i - 1].x) * (x - a[i - 1].x) + (a[i].y - a[i - 1].y) * (y - a[i - 1].y) <= 0) continue; double k, k2; k = sqrt((a[i].x - a[i - 1].x) * (a[i].x - a[i - 1].x) + (a[i].y - a[i - 1].y) * (a[i].y - a[i - 1].y)); k2 = fabs((a[i - 1].x - x) * (a[i].y - y) - (a[i - 1].y - y) * (a[i].x - x)); r = min(r, k2 / k); } printf("%.15lf\n", (R * R - r * r) * acos(-1.0)); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long M = 500 + 7, mod = 1e9 + 7; long long n, rootx, rooty; vector<pair<long long, long long>> v; long double findis(long long x1, long long y1, long long x2, long long y2) { long double d = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); d = sqrt(d); return d; } long double finperd(long long i) { long long A = v[i].second - v[i + 1].second; long long B = v[i + 1].first - v[i].first; long long C = v[i].first * v[i + 1].second - v[i].second * v[i + 1].first; long long num = A * rootx + B * rooty + C; long double deno = A * A + B * B; deno = sqrt(deno); long double perd = abs(num) / deno; return perd; } bool ok(long long i) { long long x1 = v[i].first, x2 = v[i + 1].first, y1 = v[i].second, y2 = v[i + 1].second; long double H = findis(rootx, rooty, x1, y1); long double B = finperd(i); long double P = H * H - B * B; long double H1 = findis(rootx, rooty, x2, y2); long double P1 = H1 * H1 - B * B; P = sqrt(P); P1 = sqrt(P1); long double d1 = P + P1; long double d2 = findis(x1, y1, x2, y2); if (abs(d1 - d2) < 1e-10) return 1; return 0; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; { cin >> n; cin >> rootx >> rooty; long double mxr = INT_MAX, mir = 0; for (long long i = 1; i <= n; i++) { long long x, y; cin >> x >> y; v.push_back({x, y}); long double d = (rootx - x) * (rootx - x) + (rooty - y) * (rooty - y); d = sqrt(d); mxr = min(mxr, d); mir = max(mir, d); } v.push_back(v[0]); for (long long i = 0; i < n; i++) { if (ok(i)) { long double r = finperd(i); mir = max(mir, r); mxr = min(mxr, r); } } long double d = 3.1415926535897932384 * mir * mir - 3.1415926535897932384 * mxr * mxr; cout << setprecision(20) << d << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const long double pi = 4 * atan(1.0); const long double eps = 1e-14; long double dist(long double x1, long double y1, long double x2, long double y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } long double dist(long double A, long double B, long double C, long double x, long double y) { return (A * x + B * y + C) / (A * A + B * B) * (A * x + B * y + C); } int main() { ios_base::sync_with_stdio(0); int n; long double x0, y0; cin >> n >> x0 >> y0; long double x[n + 1], y[n + 1]; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; x[n] = x[0]; y[n] = y[0]; long double dmin = dist(x0, y0, x[0], y[0]), dmax = dist(x0, y0, x[0], y[0]); for (int i = 1; i <= n; i++) { long double OA = dist(x0, y0, x[i], y[i]); long double OB = dist(x0, y0, x[i - 1], y[i - 1]); long double OH = dist( y[i] - y[i - 1], x[i - 1] - x[i], y[i - 1] * (x[i] - x[i - 1]) - x[i - 1] * (y[i] - y[i - 1]), x0, y0); long double AB = dist(x[i], y[i], x[i - 1], y[i - 1]); dmin = min(dmin, OA); dmax = max(dmax, OA); if (OB < OA + AB && OA < OB + AB) dmin = min(dmin, OH); } cout.precision(6); cout << fixed << pi * (dmax - dmin); return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double eps = 1e-9; const int N = 1e5; complex<double> p[N], c; double ix, iy; inline double x(complex<double> a) { return real(a); } inline double y(complex<double> a) { return imag(a); } inline double inner(complex<double> a, complex<double> b) { return x(conj(a) * b); } complex<double> pSproj(complex<double> a, complex<double> b, complex<double> c) { if (abs(a - b) < eps) return a; double t = inner(c - a, b - a) / norm(b - a); if (t < 0) return a; if (t > 1) return b; return a + t * (b - a); } int main() { int n; ios::sync_with_stdio(false); cin >> n >> ix >> iy; c = complex<double>(ix, iy); for (int i = 0; i < n; i++) { cin >> ix >> iy; p[i] = complex<double>(ix, iy); } double big = 0, small = 1e9; for (int i = 0; i < n; i++) { big = max(big, abs(p[i] - c)); small = min(small, abs(pSproj(p[i], p[(i + 1) % n], c) - c)); } cout << setprecision(20) << PI * big * big - PI * small * small << endl; }
#include <bits/stdc++.h> using namespace std; const double INF = 100000000000000000.0; const double PI = acos(-1.0); int n; const double EPS = 1e-12; struct PT { double x, y; PT() {} PT(double x, double y) : x(x), y(y) {} PT(const PT &p) : x(p.x), y(p.y) {} PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); } PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); } PT operator*(double c) const { return PT(x * c, y * c); } PT operator/(double c) const { return PT(x / c, y / c); } }; double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; } double norm(PT p) { return sqrt(dot(p, p)); } double dist2(PT p, PT q) { return dot(p - q, p - q); } PT ProjectPointSegment(PT a, PT b, PT c) { double r = dot(b - a, b - a); if (fabs(r) < EPS) return a; r = dot(c - a, b - a) / r; if (r < 0) return a; if (r > 1) return b; return a + (b - a) * r; } double DistancePointSegment(PT a, PT b, PT c) { return sqrt(dist2(c, ProjectPointSegment(a, b, c))); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; cin >> n; double a, b; cin >> a >> b; double mind = INF; double maxd = 0; PT center(a, b); double x, y; cin >> x >> y; PT ant(x, y); PT orig(x, y); for (int i = 1; i < n; i++) { cin >> x >> y; PT cur(x, y); double d1 = sqrt(((cur.x - a) * (cur.x - a)) + ((cur.y - b) * (cur.y - b))); double d2 = DistancePointSegment(ant, cur, center); double d3 = sqrt(((ant.x - a) * (ant.x - a)) + ((ant.y - b) * (ant.y - b))); mind = min(d2, mind); mind = min(mind, min(d1, d3)); maxd = max(d2, maxd); maxd = max(maxd, max(d1, d3)); ant = cur; } double d1 = sqrt(((orig.x - a) * (orig.x - a)) + ((orig.y - b) * (orig.y - b))); double d2 = DistancePointSegment(ant, orig, center); double d3 = sqrt(((ant.x - a) * (ant.x - a)) + ((ant.y - b) * (ant.y - b))); mind = min(d2, mind); mind = min(mind, min(d1, d3)); maxd = max(d2, maxd); maxd = max(maxd, max(d1, d3)); double dif = ((maxd) * (maxd)) - ((mind) * (mind)); double res = PI * dif; cout << setprecision(14) << fixed << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const int MAXN = 100500; const double eps = 1e-9; int dcmp(const double x) { if (x < -eps) return -1; if (x > eps) return 1; return 0; } struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} }; bool operator==(Point a, Point b) { return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0; } Point operator-(Point a, Point b) { return Point(a.x - b.x, a.y - b.y); } double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; } double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } double norm2(Point p) { return p.x * p.x + p.y * p.y; } double square(double x) { return x * x; } double diss2(Point a, Point b, Point p) { if (dcmp(dot(p - a, b - a)) <= 0 || dcmp(dot(p - b, a - b)) <= 0) return min(norm2(a - p), norm2(b - p)); if (a == b) return norm2(a - p); return square(cross(p - a, b - a)) / norm2(a - b); } int n; Point p[MAXN], t; double dis1[MAXN], dis2[MAXN]; int main(void) { cin >> n >> t.x >> t.y; for (int i = 0; i < n; ++i) cin >> p[i].x >> p[i].y; for (int i = 0; i < n; ++i) dis1[i] = norm2(p[i] - t); for (int i = 0; i < n; ++i) dis2[i] = diss2(p[i], p[(i + 1) % n], t); double maxi = *max_element(dis1, dis1 + n); double mini = *min_element(dis2, dis2 + n); printf("%.15f\n", (maxi - mini) * pi); return 0; }
#include <bits/stdc++.h> using namespace std; struct point { double x, y; point() { x = y = 0.0; } point(double _x, double _y) : x(_x), y(_y) {} }; int n; point f[100005]; point e; vector<point> ch; struct vec { double x, y; vec() { x = y = 0.0; } vec(double _x, double _y) : x(_x), y(_y) {} }; vec toVec(point p1, point p2) { return vec(p2.x - p1.x, p2.y - p1.y); } double dot(vec a, vec b) { return (a.x * b.x + a.y * b.y); } double cross(vec a, vec b) { return a.x * b.y - a.y * b.x; } vec scale(vec v, double s) { return vec(v.x * s, v.y * s); } point translate(point p, vec v) { return point(p.x + v.x, p.y + v.y); } bool ccw(point p, point q, point r) { return (cross(toVec(p, q), toVec(p, r)) > 0); } bool collinear(point p, point q, point r) { return fabs(cross(toVec(p, q), toVec(p, r))) < 1e-9; } double norm_sq(vec v) { return v.x * v.x + v.y * v.y; } double angle(point a, point o, point b) { vec oa = toVec(o, a); vec ob = toVec(o, b); return acos(dot(oa, ob) / sqrt(norm_sq(oa) * norm_sq(ob))); } double dist(point a, point b) { double x = a.x - b.x; double y = a.y - b.y; x = x * x; y = y * y; return sqrt(x + y); } double cross(point p, point q, point r) { double ax, ay, bx, by; ax = q.x - p.x; ay = q.y - p.y; bx = r.x - p.x; by = r.y - p.y; return ax * by - ay * bx; } bool cmp(point a, point b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } bool inPolygon(point pt, const vector<point> &P) { if ((int)P.size() == 0) return false; double sum = 0; for (int i = 0; i < (int)P.size() - 1; i++) { if (ccw(pt, P[i], P[i + 1])) sum += angle(P[i], pt, P[i + 1]); else sum -= angle(P[i], pt, P[i + 1]); } return fabs(fabs(sum) - 2 * acos(-1)) < 1e-9; } double distToLine(point p, point a, point b, point &c) { vec ap = toVec(a, p); vec ab = toVec(a, b); double u = dot(ap, ab) / norm_sq(ab); c = translate(a, scale(ab, u)); return dist(p, c); } double distToLineSegment(point p, point a, point b, point &c) { vec ap = toVec(a, p); vec ab = toVec(a, b); double u = dot(ap, ab) / norm_sq(ab); if (u < 0.0) { c = point(a.x, a.y); return dist(p, a); } if (u > 1.0) { c = point(b.x, b.y); return dist(p, b); } return distToLine(p, a, b, c); } void convexhull() { sort(f, f + n, cmp); ch.clear(); for (int i = 0; i < n; i++) { while (ch.size() >= 2 && cross(ch[ch.size() - 2], ch.back(), f[i]) <= 0) ch.pop_back(); ch.push_back(f[i]); } int bef = ch.size() + 1; for (int i = n - 2; i >= 0; i--) { while (ch.size() >= bef && cross(ch[ch.size() - 2], ch.back(), f[i]) <= 0) ch.pop_back(); ch.push_back(f[i]); } } int main() { scanf("%d%lf%lf", &n, &e.x, &e.y); double maxr = -1e18, minr = 1e18; for (int i = 0; i < n; i++) { scanf("%lf%lf", &f[i].x, &f[i].y); maxr = max(dist(e, f[i]), maxr); } for (int i = 0; i < n - 1; i++) { point tmp; double temp = distToLineSegment(e, f[i], f[i + 1], tmp); minr = min(minr, dist(e, tmp)); } point tmp; double temp = distToLineSegment(e, f[0], f[n - 1], tmp); minr = min(minr, dist(e, tmp)); convexhull(); if (inPolygon(e, ch)) minr = 0; double areabig = acos(-1) * maxr * maxr; double areasmall = acos(-1) * minr * minr; printf("%.20lf\n", areabig - areasmall); return 0; }
#include <bits/stdc++.h> using namespace std; long long n; const int maxn = 1e5 + 100; const double pi = 3.1415926535897932384626433832795028841971693993751; double x[maxn], y[maxn], x1, y11, max1, min1, a, b, c, p, h2, a2; double d2(double xi, double yi, double xf, double yf) { return (xf - xi) * (xf - xi) + (yf - yi) * (yf - yi); } double d(double xi, double yi, double xf, double yf) { return sqrt((xf - xi) * (xf - xi) + (yf - yi) * (yf - yi)); } int main() { cin >> n >> x1 >> y11; cin >> x[0] >> y[0]; max1 = (x[0] - x1) * (x[0] - x1) + (y[0] - y11) * (y[0] - y11); min1 = (x[0] - x1) * (x[0] - x1) + (y[0] - y11) * (y[0] - y11); for (int i = 1; i < n; i++) { cin >> x[i] >> y[i]; max1 = max((x[i] - x1) * (x[i] - x1) + (y[i] - y11) * (y[i] - y11), max1); if (d2(x1, y11, x[i], y[i]) >= d2(x1, y11, x[i - 1], y[i - 1]) + d2(x[i - 1], y[i - 1], x[i], y[i]) || d2(x1, y11, x[i - 1], y[i - 1]) >= d2(x1, y11, x[i], y[i]) + d2(x[i - 1], y[i - 1], x[i], y[i])) min1 = min((x[i] - x1) * (x[i] - x1) + (y[i] - y11) * (y[i] - y11), min1); else { a = d(x[i - 1], y[i - 1], x[i], y[i]); b = d(x1, y11, x[i], y[i]); c = d(x1, y11, x[i - 1], y[i - 1]); a2 = d2(x[i - 1], y[i - 1], x[i], y[i]); p = (a + b + c) / 2; h2 = 4 * p * (p - a) * (p - b) * (p - c) / a2; min1 = min(h2, min1); } } if (d2(x1, y11, x[0], y[0]) >= d2(x1, y11, x[n - 1], y[n - 1]) + d2(x[n - 1], y[n - 1], x[0], y[0]) || d2(x1, y11, x[n - 1], y[n - 1]) >= d2(x1, y11, x[0], y[0]) + d2(x[n - 1], y[n - 1], x[0], y[0])) min1 = min((x[0] - x1) * (x[0] - x1) + (y[0] - y11) * (y[0] - y11), min1); else { a = d(x[n - 1], y[n - 1], x[0], y[0]); b = d(x1, y11, x[0], y[0]); c = d(x1, y11, x[n - 1], y[n - 1]); a2 = d2(x[n - 1], y[n - 1], x[0], y[0]); p = (a + b + c) / 2; h2 = 4 * p * (p - a) * (p - b) * (p - c) / a2; min1 = min(h2, min1); } cout.precision(12); cout << pi * (max1 - min1); }
#include <bits/stdc++.h> constexpr auto PI = 3.141592653589793238462643383279502884L; template <typename T> T Clamp(T v, T min, T max) { return std::min<T>(max, std::max<T>(min, v)); } double Dist(double x, double y) { return std::sqrt(x * x + y * y); } double Dist(double x1, double y1, double x2, double y2) { return Dist(x1 - x2, y1 - y2); } double DistToLineSegment(double x0, double y0, double x1, double y1, double x2, double y2) { auto x01 = x0 - x1; auto y01 = y0 - y1; auto x21 = x2 - x1; auto y21 = y2 - y1; auto dot = x01 * x21 + y01 * y21; auto len2 = x21 * x21 + y21 * y21; double t = (len2 == 0) ? 0 : Clamp<double>(dot / len2, 0, 1); return Dist(x0, y0, x1 + t * x21, y1 + t * y21); } double Area(double r) { return PI * r * r; } struct Point { double x; double y; }; int main() { int64_t n; double x0, y0; std::cin >> n >> x0 >> y0; std::vector<Point> p(n); for (int64_t i = 0; i < n; i++) { double x, y; std::cin >> x >> y; p[i] = Point{x, y}; } double rmin = std::numeric_limits<double>::infinity(); double rmax = -rmin; for (int64_t i = 0; i < n; i++) { rmax = std::max(rmax, Dist(x0, y0, p[i].x, p[i].y)); int64_t j = (i + 1) % n; rmin = std::min(rmin, DistToLineSegment(x0, y0, p[i].x, p[i].y, p[j].x, p[j].y)); } printf("%.18f\n", Area(rmax) - Area(rmin)); }
#include <bits/stdc++.h> using namespace std; long double dist(pair<long double, long double> p1, pair<long double, long double> p2) { long double d1 = p1.first - p2.first; long double d2 = p1.second - p2.second; return sqrt(d1 * d1 + d2 * d2); } long double getMinDist(pair<long double, long double> p1, pair<long double, long double> p2, pair<long double, long double> p) { long double d1 = dist(p1, p); long double d2 = dist(p2, p); pair<long double, long double> mid1, mid2; long double d3, d4; long double mn = min(d1, d2); for (int i = 0; i < 30; i++) { mid1 = {p1.first - (p1.first - p2.first) * 1.0 / 3.0, p1.second - (p1.second - p2.second) * 1.0 / 3.0}; mid2 = {p1.first - (p1.first - p2.first) * 2.0 / 3.0, p1.second - (p1.second - p2.second) * 2.0 / 3.0}; d3 = dist(mid1, p); d4 = dist(mid2, p); mn = min(mn, d3); mn = min(mn, d4); if (d3 < d4) { p2 = mid2; } else { p1 = mid1; } } return mn; } pair<long double, long double> A[1000010]; int main(int argc, char const *argv[]) { pair<long double, long double> P, t; long double mn = 1e18, mx = 0; int n; cin >> n; cin >> P.first >> P.second; for (int i = 0; i < n; i++) { cin >> A[i].first >> A[i].second; mn = min(mn, dist(A[i], P)); mx = max(mx, dist(A[i], P)); } mn = min(mn, getMinDist(A[0], A[n - 1], P)); for (int i = 0; i < n - 1; i++) { mn = min(mn, getMinDist(A[i + 1], A[i], P)); } long double ans = acos(0) * 2 * (mx * mx - mn * mn); cout << fixed << setprecision(12); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<pair<double, double>> v; double dist(pair<double, double> a, pair<double, double> b) { double aux = a.first - b.first; aux *= aux; double aux2 = a.second - b.second; aux2 *= aux2; return sqrt(aux + aux2); } double Dot(pair<double, double> a, pair<double, double> b) { return a.first * b.first + a.second * b.second; } double cross(pair<double, double> a, pair<double, double> b) { return a.first * b.second - a.second * b.first; } double dist_line(pair<double, double> p, pair<double, double> a, pair<double, double> b) { pair<double, double> u, v, w, z; u = {b.first - a.first, b.second - a.second}; v = {p.first - a.first, p.second - a.second}; w = {p.first - b.first, p.second - b.second}; z = {a.first - b.first, a.second - b.second}; if (Dot(u, w) > 0) return dist(p, b); if (Dot(z, v) > 0) return dist(p, a); return fabs(cross(u, v)) / dist(a, b); } int main() { ios_base::sync_with_stdio(0); int n, i; double maxD = 0, minD = 1e9; pair<double, double> aux, p; cin >> n >> p.first >> p.second; for (i = 0; i < n; i++) { cin >> aux.first >> aux.second; v.emplace_back(aux); } for (int i = 0; i < n; i++) { double d = dist(p, v[i]); maxD = max(maxD, d); minD = min(minD, d); } for (i = 0; i < n; i++) { double d = dist_line(p, v[i], v[(i + 1) % n]); maxD = max(maxD, d); minD = min(minD, d); } cout.precision(10); cout << fixed << (maxD * maxD - minD * minD) * 3.14159265358979323846 << "\n"; return 0; }
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const double EPS = 1e-15; const double PI = acos(-1.0); const int MAXN = (int)1e5 + 7; const int INF = (int)1e9 + 7; const long long LINF = (long long)2e18 + 7; const int MOD = (int)1e9 + 7; const unsigned long long P = 239017; const unsigned long long MM = (unsigned long long)2147482661; struct pt { long long x, y; }; struct segm { pt p1, p2; }; int n; pt p, a[MAXN]; double distpt(double x1, double y1, double x2, double y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } double highdist(pt p, segm seg) { long long x1 = seg.p1.x, x2 = seg.p2.x, y1 = seg.p1.y, y2 = seg.p2.y; return max(distpt(p.x, p.y, x1, y1), distpt(p.x, p.y, x2, y2)); } double lowdist(pt p, segm seg) { long long x1 = seg.p1.x, x2 = seg.p2.x, y1 = seg.p1.y, y2 = seg.p2.y; long long dx = (x2 - x1), dy = (y2 - y1); long long a = dy, b = -dx, c = y2 * dx - x2 * dy; long long na = b, nb = -a, nc = -(na * p.x + nb * p.y); double x = -1.0 * (c * nb - nc * b) / (a * nb - na * b); double y = -1.0 * (a * nc - na * c) / (a * nb - na * b); if (x < min(x1, x2) || x > max(x1, x2)) { return min(distpt(p.x, p.y, x1, y1), distpt(p.x, p.y, x2, y2)); } return distpt(p.x, p.y, x, y); } int main() { cin >> n >> p.x >> p.y; for (int i = 0; i < (int)n; i++) { scanf("%I64d%I64d", &a[i].x, &a[i].y); } double maxdist = 0, mindist = LINF; for (int i = 0; i < (int)n; i++) { int j = (i + 1) % n; segm sg = {a[i], a[j]}; maxdist = max(maxdist, highdist(p, sg)); mindist = min(mindist, lowdist(p, sg)); } printf("%.10f", PI * (maxdist - mindist)); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; const long double pi = acos(-1.0); long double n, x, y; struct point { long double x, y; point(long double vx, long double vy) { x = vx, y = vy; } point() {} } p[N]; point operator-(const point& v1, const point& v2) { return point(v2.x - v1.x, v2.y - v1.y); } long double product(point a, point b) { return a.x * b.y - a.y * b.x; } long double dot(point a, point b) { return a.x * b.x + a.y * b.y; } long double dis(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i <= n; i++) cin >> p[i].x >> p[i].y; long double mn = 1e18, mx = 0; for (int i = 1; i <= n; i++) { int j = (i == n ? 1 : i + 1); mx = max(mx, dis(p[0], p[i])); point ap = p[0] - p[i], ab = p[j] - p[i]; point ba = p[i] - p[j], bp = p[0] - p[j]; if (dot(ap, ab) < 0) { mn = min(mn, dis(p[0], p[i])); continue; } if (dot(ba, bp) < 0) { mn = min(mn, dis(p[0], p[j])); continue; } long double s = fabs(product(ap, ab)) / dis(p[i], p[j]); mn = min(mn, s); } long double res = pi * (mx * mx - mn * mn); cout << fixed << setprecision(15) << res << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); class PT { public: double x, y; PT() {} PT(double x, double y) : x(x), y(y) {} PT(const PT &p) : x(p.x), y(p.y) {} double Magnitude() { return sqrt(x * x + y * y); } PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); } PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); } PT operator*(double c) const { return PT(x * c, y * c); } PT operator/(double c) const { return PT(x / c, y / c); } }; double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; } double dist2(PT p, PT q) { return dot(p - q, p - q); } double dist(PT p, PT q) { return sqrt(dist2(p, q)); } double cross(PT p, PT q) { return p.x * q.y - p.y * q.x; } double myAsin(double a, double b) { if (a / b > 1) return PI * 0.5; if (a / b < -1) return -PI * 0.5; return asin(a / b); } double myAtan(double a, double b) { if (b == 0) return PI * 0.5; return atan(a / b); } ostream &operator<<(ostream &os, const PT &p) { os << "(" << p.x << "," << p.y << ")"; } PT scale(PT p, PT pivot, double c) { PT trans = p - pivot; trans = (trans * c) / trans.Magnitude(); return trans + pivot; } PT RotateCCW90(PT p) { return PT(-p.y, p.x); } PT RotateCW90(PT p) { return PT(p.y, -p.x); } PT RotateCCW(PT p, double t) { return PT(p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t)); } PT RotateAroundPointCCW(PT p, PT pivot, double t) { PT trans = p - pivot; PT ret = RotateCCW(trans, t); ret = ret + pivot; return ret; } PT Reflection(PT ray, PT normal) { ray = ray / ray.Magnitude(); normal = normal / normal.Magnitude(); return normal * (2 * dot(ray, normal)) - ray; } PT ProjectPointLine(PT a, PT b, PT c) { return a + (b - a) * dot(c - a, b - a) / dot(b - a, b - a); } double DistancePointLine(PT a, PT b, PT c) { return dist(c, ProjectPointLine(a, b, c)); } PT ProjectPointSegment(PT a, PT b, PT c) { double r = dot(b - a, b - a); if (fabs(r) < 1e-12) return a; r = dot(c - a, b - a) / r; if (r < 0) return a; if (r > 1) return b; return a + (b - a) * r; } double DistancePointSegment(PT a, PT b, PT c) { return sqrt(dist2(c, ProjectPointSegment(a, b, c))); } double DistancePointPlane(double x, double y, double z, double a, double b, double c, double d) { return fabs(a * x + b * y + c * z - d) / sqrt(a * a + b * b + c * c); } bool LinesParallel(PT a, PT b, PT c, PT d) { return fabs(cross(b - a, c - d)) < 1e-12; } bool LinesCollinear(PT a, PT b, PT c, PT d) { return LinesParallel(a, b, c, d) && fabs(cross(a - b, a - c)) < 1e-12 && fabs(cross(c - d, c - a)) < 1e-12; } bool SegmentsIntersect(PT a, PT b, PT c, PT d) { if (LinesCollinear(a, b, c, d)) { if (dist2(a, c) < 1e-12 || dist2(a, d) < 1e-12 || dist2(b, c) < 1e-12 || dist2(b, d) < 1e-12) return true; if (dot(c - a, c - b) > 0 && dot(d - a, d - b) > 0 && dot(c - b, d - b) > 0) return false; return true; } if (cross(d - a, b - a) * cross(c - a, b - a) > 0) return false; if (cross(a - c, d - c) * cross(b - c, d - c) > 0) return false; return true; } PT ComputeLineIntersection(PT a, PT b, PT c, PT d) { b = b - a; d = c - d; c = c - a; assert(dot(b, b) > 1e-12 && dot(d, d) > 1e-12); return a + b * cross(c, d) / cross(b, d); } PT ComputeCircleCenter(PT a, PT b, PT c) { b = (a + b) / 2; c = (a + c) / 2; return ComputeLineIntersection(b, b + RotateCW90(a - b), c, c + RotateCW90(a - c)); } bool PointInPolygon(const vector<PT> &p, PT q) { bool c = 0; for (int i = 0; i < p.size(); i++) { int j = (i + 1) % p.size(); if ((p[i].y <= q.y && q.y < p[j].y || p[j].y <= q.y && q.y < p[i].y) && q.x < p[i].x + (p[j].x - p[i].x) * (q.y - p[i].y) / (p[j].y - p[i].y)) c = !c; } return c; } bool PointOnPolygon(const vector<PT> &p, PT q) { for (int i = 0; i < p.size(); i++) if (dist2(ProjectPointSegment(p[i], p[(i + 1) % p.size()], q), q) < 1e-12) return true; return false; } double ComputeSignedArea(const vector<PT> &p) { double area = 0; for (int i = 0; i < p.size(); i++) { int j = (i + 1) % p.size(); area += p[i].x * p[j].y - p[j].x * p[i].y; } return area / 2.0; } double ComputeArea(const vector<PT> &p) { return fabs(ComputeSignedArea(p)); } bool IsSimple(const vector<PT> &p) { for (int i = 0; i < p.size(); i++) { for (int k = i + 1; k < p.size(); k++) { int j = (i + 1) % p.size(); int l = (k + 1) % p.size(); if (i == l || j == k) continue; if (SegmentsIntersect(p[i], p[j], p[k], p[l])) return false; } } return true; } double PAngle(PT a, PT b, PT c) { PT temp1(a.x - b.x, a.y - b.y), temp2(c.x - b.x, c.y - b.y); double ans = asin((temp1.x * temp2.y - temp1.y * temp2.x) / (temp1.Magnitude() * temp2.Magnitude())); if ((ans < 0 && (temp1.x * temp2.x + temp1.y * temp2.y) < 0) || (ans >= 0 && (temp1.x * temp2.x + temp1.y * temp2.y) < 0)) ans = PI - ans; ans = ans < 0 ? 2 * PI + ans : ans; return ans; } double SignedArea(PT a, PT b, PT c) { PT temp1(b.x - a.x, b.y - a.y), temp2(c.x - a.x, c.y - a.y); return 0.5 * (temp1.x * temp2.y - temp1.y * temp2.x); } vector<PT> v; PT cen, p; int main() { int n, i, j, k, l; double x, y; cin >> n; cin >> cen.x >> cen.y; for (i = 0; i < n; i++) { cin >> x >> y; p.x = x; p.y = y; v.push_back(p); } double maxx = 0.0, minn = 1e9; for (i = 0; i < n; i++) { maxx = max(maxx, sqrt(dist2(cen, v[i]))); double now = DistancePointSegment(v[i], v[(i + 1) % n], cen); minn = min(minn, now); } double ans = acos(-1.0) * (maxx * maxx - minn * minn); printf("%.10f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const long long inf = 1e16; const int MOD = 1e9 + 7; const double PI = atan(1) * 4; const int N = 1e5 + 10; long long sqr(long long x) { return x * x; } pair<int, int> operator-(pair<int, int> a, pair<int, int> b) { return pair<int, int>(a.first - b.first, a.second - b.second); } long long sqrmodule(pair<int, int> a) { return sqr(a.first) + sqr(a.second); } long long operator%(pair<int, int> a, pair<int, int> b) { return 1LL * a.first * b.second - 1LL * a.second * b.first; } pair<int, int> p[N]; int n; double solve() { long long ma = 0; double mi = inf; p[n + 1] = p[1]; for (auto i = (1); i <= (n); i++) { long long cur = sqrmodule(p[0] - p[i]); ma = max(ma, cur); mi = min(mi, sqrt(cur)); long long lena = sqrmodule(p[i] - p[0]), lenb = sqrmodule(p[i + 1] - p[0]), lenc = (sqrmodule(p[i] - p[i + 1])); if (lena > lenb) swap(lena, lenb); if (lena + lenc > lenb) { mi = min(mi, abs((p[i] - p[0]) % (p[i + 1] - p[0])) / sqrt(lenc)); } } return PI * (ma - mi * mi); } int main() { scanf("%d", &n); for (auto i = (0); i <= (n); i++) scanf("%d%d", &p[i].first, &p[i].second); printf("%.12f", solve()); }
#include <bits/stdc++.h> using namespace std; pair<long long, long long> a[200005]; vector<long long> v; vector<double> v1; pair<long long, long long> p; long long sqr(long long k) { long long ret = k * k; return ret; } double sqr1(double k) { double ret = k * k; return ret; } void fun(pair<long long, long long> p1, pair<long long, long long> p2, double x, double y) { long long m1 = min(p1.first, p2.first); long long m2 = max(p1.first, p2.first); long long m3 = min(p1.second, p2.second); long long m4 = max(p1.second, p2.second); if (x >= m1 && x <= m2 && y >= m3 && y <= m4) { v1.push_back(sqr1(p.first - x) + sqr1(p.second - y)); } else { v1.push_back(sqr1(p.first - p1.first) + sqr1(p.second - p1.second)); v1.push_back(sqr1(p.first - p2.first) + sqr1(p.second - p2.second)); } } int main() { long long n, i, j; scanf("%lld", &n); scanf("%lld %lld", &p.first, &p.second); for (i = 0; i < n; i++) { scanf("%lld %lld", &a[i].first, &a[i].second); } if (n == 1) { printf("0\n"); return 0; } for (i = 0; i < n; i++) { v.push_back(sqr(a[i].first - p.first) + sqr(a[i].second - p.second)); } sort(v.begin(), v.end()); double r2 = v[n - 1]; for (i = 0; i < n; i++) { long long nxt = (i + 1) % n; double a1, b, c, slope, x, y; if (a[i].first == a[nxt].first) { a1 = 1; b = 0; c = -a[i].first; } else { slope = (double)(a[i].second - a[nxt].second) / (a[i].first - a[nxt].first); a1 = slope; b = -1; c = a[i].second - slope * a[i].first; } x = (double)(b * (b * p.first - a1 * p.second) - a1 * c) / (a1 * a1 + b * b); y = (double)(a1 * (a1 * p.second - b * p.first) - b * c) / (a1 * a1 + b * b); fun(a[i], a[nxt], x, y); } sort(v1.begin(), v1.end()); double r1 = v1[0]; double A1 = r1 * 3.141592653589793; double A2 = r2 * 3.141592653589793; A2 -= A1; printf("%.9lf\n", A2); return 0; }
#include <bits/stdc++.h> using namespace std; int x, y; struct Point { long double x, y; }; struct Line { long double a, b, c; }; void setline(Line &l, Point &a, Point &b) { l.a = a.y - b.y; l.b = -(a.x - b.x); l.c = a.x * b.y - a.y * b.x; } long double Distance(Point &a, Point &b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } long double Distance(Point &p, Line &l) { return abs(l.a * p.x + l.b * p.y + l.c) / sqrt(l.a * l.a + l.b * l.b); } long double cos3p(Point &a, Point &P, Point &b) { return (Distance(a, P) * Distance(a, P) + Distance(b, P) * Distance(b, P) - Distance(a, b) * Distance(a, b)) / (2 * Distance(a, P) * Distance(b, P)); } bool cmp(const Point &a, const Point &b) { return (a.x - x) * (a.x - x) + (a.y - y) * (a.y - y) < (b.x - x) * (b.x - x) + (b.y - y) * (b.y - y); } Point nn[100005]; int main() { int n; cin >> n >> x >> y; for (int i = 0; i < n; i++) { cin >> nn[i].x >> nn[i].y; } Line ll; Point p0; p0.x = x, p0.y = y; long double large = Distance(p0, nn[n - 1]), small = Distance(p0, nn[n - 1]); if (cos3p(p0, nn[0], nn[n - 1]) * cos3p(p0, nn[n - 1], nn[0]) >= 0) { setline(ll, nn[0], nn[n - 1]); small = min(small, Distance(p0, ll)); } for (int i = 0; i < n - 1; i++) { large = max(large, Distance(p0, nn[i])); small = min(small, Distance(p0, nn[i])); if (cos3p(p0, nn[i], nn[i + 1]) * cos3p(p0, nn[i + 1], nn[i]) > 0) { setline(ll, nn[i], nn[i + 1]); small = min(small, Distance(p0, ll)); } } cout << setprecision(20) << ((long double)acos(-1.0)) * (large * large - small * small) << endl; return 0; }