text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return (y ? gcd(y, x % y) : x); }
long long lcm(long long x, long long y) { return x * (y / gcd(x, y)); }
const long double Pi = 3.14159265358979323846;
long double distance(long double x, long double y, long double x1,
long double y1, long double x2, long double y2) {
long double A = x - x1;
long double B = y - y1;
long double C = x2 - x1;
long double D = y2 - y1;
long double dot = A * C + B * D;
long double len_sq = C * C + D * D;
long double param = -1;
long double xx, yy;
if (len_sq != 0.0) param = dot / len_sq;
if (param < 0.0) {
xx = x1;
yy = y1;
} else if (param > 1.0) {
xx = x2;
yy = y2;
} else {
xx = x1 + param * C;
yy = y1 + param * D;
}
long double dx = x - xx;
long double dy = y - yy;
return dx * dx + dy * dy;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, x, y;
cin >> n >> x >> y;
long double r1 = 1e15, r2 = -100000000000;
vector<pair<long double, long double>> a(n + 1);
for (int i = 0; i < n; i++) {
long long x1, y1;
cin >> x1 >> y1;
a[i].first = x1 - x;
a[i].second = y1 - y;
if (i == 0) {
a[n].first = x1 - x;
a[n].second = y1 - y;
}
r2 = max(r2, (a[i].first * a[i].first) + (a[i].second * a[i].second));
}
for (int i = 1; i < n + 1; i++) {
r1 = min(r1, distance(0, 0, a[i - 1].first, a[i - 1].second, a[i].first,
a[i].second));
}
long double ans = Pi * ((r2 - r1) * 1.0);
cout << setprecision(15) << ans << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline void in() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
inline void out() {
fclose(stdin);
fclose(stdout);
}
const int MAXN = 100004;
const double eps = 1e-7;
int N;
double px, py;
double x[MAXN], y[MAXN];
double xx, yy;
double maxi = 0, mini = 1e18;
inline double Calc(double x1, double y1, double x2, double y2) {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
inline void Solve() {
double e;
double xl, xr, yl, yr;
double x1, y1, x2, y2;
double d1 = 1.0 / 3.0, d2 = 2.0 / 3.0;
for (register int i = 1; i <= N; i++) scanf("%lf%lf", &x[i], &y[i]);
x[0] = x[N], y[0] = y[N];
for (register int i = 1; i <= N; i++) {
xl = x[i], yl = y[i], xr = x[i - 1], yr = y[i - 1];
while (fabs(xl - xr) + fabs(yl - yr) > eps) {
x1 = xl + (xr - xl) * d1, y1 = yl + (yr - yl) * d1;
x2 = xl + (xr - xl) * d2, y2 = yl + (yr - yl) * d2;
if (Calc(x1, y1, px, py) < Calc(x2, y2, px, py))
xr = x2, yr = y2;
else
xl = x1, yl = y1;
}
e = Calc(xl, yl, px, py);
maxi = max(e, maxi), mini = min(e, mini);
xl = x[i], yl = y[i], xr = x[i - 1], yr = y[i - 1];
while (fabs(xl - xr) + fabs(yl - yr) > eps) {
x1 = xl + (xr - xl) * d1, y1 = yl + (yr - yl) * d1;
x2 = xl + (xr - xl) * d2, y2 = yl + (yr - yl) * d2;
if (Calc(x1, y1, px, py) < Calc(x2, y2, px, py))
xl = x1, yl = y1;
else
xr = x2, yr = y2;
}
e = Calc(xl, yl, px, py);
maxi = max(e, maxi), mini = min(e, mini);
}
printf("%.10lf\n", (maxi - mini) * acos(-1));
}
int main() {
scanf("%d", &N);
scanf("%lf%lf", &px, &py);
Solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
ld r = 1e50, R = -1;
const ld pi = acos(-1);
ld sqr(ld x) { return x * x; }
struct point {
ld x, y;
void read() { cin >> x >> y; }
point operator-(point& b) { return {x - b.x, y - b.y}; }
ld norm() { return sqrt(x * x + y * y); }
} o, p[100003];
inline ld det(const point& a, const point& b) { return a.x * b.y - a.y * b.x; }
inline ld dot(const point& a, const point& b) { return a.x * b.x + a.y * b.y; }
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
o.read();
for (int i = 0; i < n; ++i) {
p[i].read();
R = max(R, (p[i] - o).norm());
}
p[n] = *p;
for (int i = 0; i < n; ++i) {
if (dot(o - p[i], p[i + 1] - p[i]) < 0)
r = min(r, (o - p[i]).norm());
else if (dot(o - p[i + 1], p[i] - p[i + 1]) < 0)
r = min(r, (o - p[i + 1]).norm());
else
r = min(r, abs(det(p[i] - o, p[i + 1] - o) / (p[i] - p[i + 1]).norm()));
}
cout << setprecision(30) << (R * R - r * r) * pi;
}
|
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y, dis;
Point() {}
Point(double a, double b) {
x = a;
y = b;
}
} C[1000005];
double c_x, c_y;
int n;
double dis(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
double dis2(Point a, Point b, Point c) {
double k1 = dis(a, b), k2 = dis(a, c), k3 = dis(b, c);
if (k1 >= k2 + k3) return k2;
if (k2 >= k1 + k3) return k1;
double d = fabs((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x));
return d * d / k3;
}
int main() {
cin >> n >> c_x >> c_y;
Point p(c_x, c_y);
double MAX = 0;
double Min = 1e18;
for (int i = 0; i < n; i++) {
double a, b;
cin >> a >> b;
C[i].x = a;
C[i].y = b;
C[i].dis = dis(p, C[i]);
if (MAX < dis(p, C[i])) MAX = dis(p, C[i]);
if (Min > dis(p, C[i])) Min = dis(p, C[i]);
}
for (int i = 0; i < n; i++) {
if (Min > dis2(p, C[i], C[(i + 1) % n]))
Min = dis2(p, C[i], C[(i + 1) % n]);
}
printf("%.18lf\n", acos(-1) * (MAX - Min));
}
|
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
int id;
} pot[100000], po;
int n;
double cross(Point p, Point p1, Point p2) {
double x1 = p1.x - p.x, y1 = p1.y - p.y;
double x2 = p2.x - p.x, y2 = p2.y - p.y;
return x1 * y2 - x2 * y1;
}
double dis2(Point p1, Point p2) {
return sqrt(pow(p1.x - p2.x, 2.0) + pow(p1.y - p2.y, 2.0));
}
double disptoseg(Point p, Point p1, Point p2) {
if (dis2(p1, p2) == 0) return dis2(p, p1);
Point t = po;
t.y += p1.x - p2.x;
t.x += p2.y - p1.y;
if (cross(t, p, p1) * cross(t, p, p2) >= 0) {
return min(dis2(p, p1), dis2(p, p2));
}
return fabs(cross(p, p1, p2)) / dis2(p1, p2);
}
int main() {
cin >> n >> po.x >> po.y;
{
for (int i = 0; i < n; ++i) {
cin >> pot[i].x >> pot[i].y;
}
pot[n] = pot[0];
double ans = 1e30;
double mmax = 0;
double tmp;
for (int i = 0; i < n; ++i) {
tmp = disptoseg(po, pot[i], pot[i + 1]);
if (tmp < ans) ans = tmp;
tmp = dis2(po, pot[i]);
if (tmp > mmax) mmax = tmp;
}
printf("%.20f\n", ((mmax * mmax) - (ans * ans)) *
3.141592653589793238462643383279502884);
}
return 0;
}
|
#include <bits/stdc++.h>
const long double pi = acos(-1.0);
using namespace std;
long double distance(long long x1, long long y1, long long x2, long long y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
long double mina(long double a, long double b) {
if (a < b)
return a;
else
return b;
}
long double maxa(long double a, long double b) {
if (a > b)
return a;
else
return b;
}
int main() {
long long n;
long double x, y;
vector<pair<long double, long double>> a;
cin >> n >> x >> y;
a.resize(n + 1);
for (long long i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
a[0] = a[n];
long double max = -1;
long double min = 1E18;
for (long long i = 0; i < n; i++) {
long double d = distance(x, y, a[i].first, a[i].second);
if (d > max) max = d;
if (d < min) min = d;
}
for (long long i = 1; i <= n; i++) {
long double a1 = a[i].second - a[i - 1].second;
long double b1 = a[i - 1].first - a[i].first;
long double c1 = -a[i].first * a1 - a[i].second * b1;
long double a2 = b1, b2 = -a1, c2 = -x * a2 - y * b2;
long double x1 = -(c1 * b2 - c2 * b1) / (a1 * b2 - a2 * b1);
long double y1 = -(a1 * c2 - a2 * c1) / (a1 * b2 - a2 * b1);
if (x1 >= mina(a[i].first, a[i - 1].first) &&
(x1 <= maxa(a[i].first, a[i - 1].first)) &&
(y1 >= mina(a[i].second, a[i - 1].second)) &&
(y1 <= maxa(a[i].second, a[i - 1].second))) {
long double d = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
if (d < min) min = d;
}
}
cout.precision(12);
cout << pi * (max * max - min * min);
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-6;
int n;
pair<int, int> p;
pair<int, int> pt[100100];
double dist(double x, double y) { return sqrt(x * x + y * y); }
double distTo(pair<int, int> a, pair<int, int> b) {
double res = dist(p.first - a.first, p.second - a.second);
res = min(res, dist(p.first - b.first, p.second - b.second));
double A1 = a.second - b.second;
double B1 = b.first - a.first;
double C1 = -A1 * a.first - B1 * a.second;
double A2 = B1;
double B2 = -A1;
double C2 = -A2 * p.first - B2 * p.second;
double X = (B1 * C2 - B2 * C1) / (A1 * B2 - A2 * B1);
double Y = (C1 * A2 - C2 * A1) / (A1 * B2 - A2 * B1);
if (X + EPS > min(a.first, b.first) && X - EPS < max(a.first, b.first) &&
Y + EPS > min(a.second, b.second) && Y - EPS < max(a.second, b.second))
res = min(res, dist(p.first - X, p.second - Y));
return res;
}
int main() {
scanf("%d%d%d", &n, &p.first, &p.second);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &pt[i].first, &pt[i].second);
}
double R = -1, r = 1e9;
for (int i = 0; i < n; ++i) {
R = max(R, dist(p.first - pt[i].first, p.second - pt[i].second));
r = min(r, distTo(pt[i], pt[(i + 1) % n]));
}
printf("%.20f\n", PI * (R * R - r * r));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double INF = 1e308;
const int IT = 50;
const int N = 100000;
double x[N + 1], y[N + 1];
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double findMin(double x1, double y1, double x2, double y2, double x3,
double y3) {
double l = 0, r = 1;
for (int it = 0; it < IT; it++) {
double m1 = l + (r - l) / 3;
double m2 = r - (r - l) / 3;
if (dist(x1 + m1 * (x2 - x1), y1 + m1 * (y2 - y1), x3, y3) <
dist(x1 + m2 * (x2 - x1), y1 + m2 * (y2 - y1), x3, y3))
r = m2;
else
l = m1;
}
return dist(x1 + l * (x2 - x1), y1 + l * (y2 - y1), x3, y3);
}
int main() {
int n;
double xp, yp;
cin >> n >> xp >> yp;
double minR = INF, maxR = -INF;
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++) {
minR = min(minR, findMin(x[i], y[i], x[i + 1], y[i + 1], xp, yp));
maxR = max(maxR, dist(x[i], y[i], xp, yp));
}
printf("%.10lf\n", M_PI * (maxR * maxR - minR * minR));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long double EPS = 1e-9;
long double pi = acos(-1.0);
long double go_rad(long double theta) { return (theta * pi / (180 + 0.0)); }
long double go_degree(long double rad) { return rad * (180.0 / pi); }
complex<long double> tovec(complex<long double> p1, complex<long double> p2) {
complex<long double> ans = {p2.real() - p1.real(), p2.imag() - p1.imag()};
return ans;
}
long double dot(complex<long double> a, complex<long double> b) {
return (a.real() * b.real() + a.imag() * b.imag());
}
long double angle(complex<long double> a, complex<long double> o,
complex<long double> b) {
complex<long double> oa = tovec(o, a), ob = tovec(o, b);
cout.precision(9);
long double ans = (dot(oa, ob) / (abs(oa) * abs(ob)));
if (abs(ans - 1.0) < 1e-9) {
ans = 1;
}
return acos(ans);
}
long double cross_product(complex<long double> v1, complex<long double> v2) {
return (conj(v1) * v2).imag();
int a;
cin >> a;
long double c1, c2;
cin >> c1 >> c2;
complex<long double> p = {c1, c2};
vector<complex<long double> > v;
for (long long int i = (long long int)(0); i < (long long int)(a); i++) {
complex<long double> asd;
cin >> c1 >> c2;
asd = {c1, c2};
v.push_back(asd);
}
}
long double point_location(complex<long double> p1, complex<long double> p2,
complex<long double> p_test) {
return cross_product(p_test - p1, p_test - p2);
}
long double dist(complex<long double> p1, complex<long double> p2) {
return (abs(p2 - p1));
}
complex<long double> rotate(complex<long double> p, long double theta) {
long double rad = go_rad(theta);
return complex<long double>(p.real() * cos(rad) - p.imag() * sin(rad),
p.real() * sin(rad) + p.imag() * cos(rad));
}
long double dist_point_line(complex<long double> s1, complex<long double> s2,
complex<long double> p) {
return abs(cross_product(s1 - p, s2 - p) / dist(s2, s1));
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a;
cin >> a;
long double c1, c2;
cin >> c1 >> c2;
complex<long double> p = {c1, c2};
vector<complex<long double> > v;
for (long long int i = (long long int)(0); i < (long long int)(a); i++) {
complex<long double> asd;
cin >> c1 >> c2;
asd = {c1, c2};
v.push_back(asd);
}
v.push_back(v[0]);
long double mini = 1e7 + 9, maxi = 0;
for (long long int i = (long long int)(0);
i < (long long int)((v).size() - 1); i++) {
long double a1 = go_degree(angle(p, v[i], v[i + 1]));
long double a2 = go_degree(angle(p, v[i + 1], v[i]));
long double d1 = dist(v[i], p);
long double d2 = dist(v[i + 1], p);
mini = min({mini, d1, d2});
maxi = max({maxi, d1, d2});
if (a1 < 90.0 and a2 < 90.0) {
long double D = dist_point_line(v[i], v[i + 1], p);
mini = min(mini, D);
maxi = max(maxi, D);
}
}
long double area = pi * (maxi * maxi - mini * mini);
cout.precision(17);
cout << fixed;
cout << area << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1);
int cmp(double x) {
if (fabs(x) < eps) return 0;
if (x > 0) return 1;
return -1;
}
int cmp(double x, double y) { return cmp(x - y); }
inline double sqr(double x) { return x * x; }
struct point {
double x, y;
point() {}
point(double a, double b) : x(a), y(b) {}
friend point operator+(const point &a, const point &b) {
return point(a.x + b.x, a.y + b.y);
}
friend point operator-(const point &a, const point &b) {
return point(a.x - b.x, a.y - b.y);
}
friend bool operator==(const point &a, const point &b) {
return cmp(a.x - b.x) == 0 && cmp(a.y - b.y) == 0;
}
friend bool operator<(const point &a, const point &b) {
if (cmp(a.x - b.x) < 0) return true;
if (cmp(a.x - b.x) > 0) return false;
return cmp(a.y - b.y) < 0;
}
friend point operator*(const point &a, const double &b) {
return point(a.x * b, a.y * b);
}
friend point operator*(const double &a, const point &b) {
return point(a * b.x, a * b.y);
}
friend point operator/(const point &a, const double &b) {
return point(a.x / b, a.y / b);
}
friend istream &operator>>(istream &fin, point &a) {
fin >> a.x >> a.y;
return fin;
}
double norm() { return sqrt(sqr(x) + sqr(y)); }
};
double det(const point &a, const point &b) { return a.x * b.y - a.y * b.x; }
double dot(const point &a, const point &b) { return a.x * b.x + a.y * b.y; }
double dist(const point &a, const point &b) { return (a - b).norm(); }
point rorate_point(const point &p, double A) {
double tx = p.x, ty = p.y;
return point(tx * cos(A) - ty * sin(A), tx * sin(A) + ty * cos(A));
}
struct line {
point a, b;
line(point x, point y) : a(x), b(y) {}
};
double dis_point_segment(const point p, const point s, const point t) {
if (cmp(dot(p - s, t - s)) < 0) return (p - s).norm();
if (cmp(dot(p - t, s - t)) < 0) return (p - t).norm();
return fabs(det(s - p, t - p) / dist(s, t));
}
void PointProjLine(const point p, const point s, const point t, point &cp) {
double r = dot((t - s), (p - s)) / dot(t - s, t - s);
cp = s + r * (t - s);
}
bool PointOnSegment(point p, point s, point t) {
return cmp(det(p - s, t - s)) == 0 && cmp(dot(p - s, p - t)) <= 0;
}
bool parallel(line a, line b) { return !cmp(det(a.a - a.b, b.a - b.b)); }
bool line_make_point(line a, line b, point &res) {
if (parallel(a, b)) return false;
double s1 = det(a.a - b.a, b.b - b.a);
double s2 = det(a.b - b.a, b.b - b.a);
res = (s1 * a.b - s2 * a.a) / (s1 - s2);
return true;
}
double multiply(point sp, point ep, point op) {
return ((sp.x - op.x) * (ep.y - op.y) - (ep.x - op.x) * (sp.y - op.y));
}
bool intersect(line u, line v) {
return ((max(u.a.x, u.b.x) >= min(v.a.x, v.b.x)) &&
(max(v.a.x, v.b.x) >= min(u.a.x, u.b.x)) &&
(max(u.a.y, u.b.y) >= min(v.a.y, v.b.y)) &&
(max(v.a.y, v.b.y) >= min(u.a.y, u.b.y)) &&
(multiply(v.a, u.b, u.a) * multiply(u.b, v.b, u.a) >= 0) &&
(multiply(u.a, v.b, v.a) * multiply(v.b, u.b, v.a) >= 0));
}
const int maxn = 10001;
struct polygon {
int n;
point a[maxn];
double perimeter() {
double sum = 0;
a[n] = a[0];
for (int i = 0; i < n; i++) sum += (a[i + 1] - a[i]).norm();
return sum;
}
double area() {
double sum = 0;
a[n] = a[0];
for (int i = 0; i < n; i++) sum += det(a[i + 1], a[i]);
return sum / 2.;
}
int Point_In(point t) {
int num = 0, i, d1, d2, k;
a[n] = a[0];
for (int i = 0; i < n; i++) {
if (PointOnSegment(t, a[i], a[i + 1])) return 2;
k = cmp(det(a[i + 1] - a[i], t - a[i]));
d1 = cmp(a[i].y - t.y);
d2 = cmp(a[i + 1].y - t.y);
if (k > 0 && d1 <= 0 && d2 > 0) num++;
if (k < 0 && d2 <= 0 && d1 > 0) num++;
}
return num & 1;
}
};
struct polygon_convex {
vector<point> P;
polygon_convex(int Size = 0) { P.resize(Size); }
};
bool comp_less(const point &a, const point &b) {
return cmp(a.x - b.x) < 0 || cmp(a.x - b.x) == 0 && cmp(a.y - b.y) < 0;
}
polygon_convex convex_hull(vector<point> a) {
polygon_convex res(2 * a.size() + 5);
sort(a.begin(), a.end(), comp_less);
a.erase(unique(a.begin(), a.end()), a.end());
int m = 0;
for (int i = 0; i < a.size(); ++i) {
while (m > 1 &&
cmp(det(res.P[m - 1] - res.P[m - 2], a[i] - res.P[m - 2])) <= 0)
--m;
res.P[m++] = a[i];
}
int k = m;
for (int i = int(a.size()) - 2; i >= 0; --i) {
while (m > k &&
cmp(det(res.P[m - 1] - res.P[m - 2], a[i] - res.P[m - 2])) <= 0)
--m;
res.P[m++] = a[i];
}
res.P.resize(m);
if (a.size() > 1) res.P.resize(m - 1);
return res;
}
int containOlogn(const polygon_convex &a, const point &b) {
int n = a.P.size();
point g = (a.P[0] + a.P[n / 3] + a.P[2 * n / 3]) / 3.0;
int l = 0, r = n;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (cmp(det(a.P[l] - g, a.P[mid] - g)) > 0) {
if (cmp(det(a.P[l] - g, b - g)) >= 0 && cmp(det(a.P[mid] - g, b - g)) < 0)
r = mid;
else
l = mid;
} else {
if (cmp(det(a.P[l] - g, b - g)) < 0 && cmp(det(a.P[mid] - g, b - g)) >= 0)
l = mid;
else
r = mid;
}
}
r %= n;
int z = cmp(det(a.P[r] - b, a.P[l] - b)) - 1;
if (z == -2) return 1;
return z;
}
bool containOn(const polygon_convex &a, const point &b) {
int n = a.P.size();
int sign = 0;
for (int i = 0; i < n; ++i) {
int x = cmp(det(a.P[i] - b, a.P[((i + 1) % n)] - b));
if (x) {
if (sign) {
if (sign != x) return false;
} else
sign = x;
}
}
return true;
}
bool inaline(line a, line b) {
if (!parallel(a, b)) return false;
if (cmp(det(a.a - a.b, a.a - b.a)) == 0) return true;
return false;
}
const double INF = 10000;
double arg(const point &p) { return atan2(p.y, p.x); }
inline double satisfy(point a, pair<point, point> p) {
return cmp(det(a - p.first, p.second - p.first)) <= 0;
}
point crosspoint(const pair<point, point> &a, const pair<point, point> &b) {
double k = det(b.first - b.second, a.first - b.second);
k = k / (k - det(b.first - b.second, a.second - b.second));
return a.first + (a.second - a.first) * k;
}
bool cmpp(const pair<point, point> &a, const pair<point, point> &b) {
int res = cmp(arg(a.second - a.first) - arg(b.second - b.first));
return res == 0 ? satisfy(a.first, b) : res < 0;
}
vector<point> HalfplaneIntersection(vector<pair<point, point> > v) {
sort(v.begin(), v.end(), cmpp);
deque<pair<point, point> > q;
deque<point> ans;
q.push_back(v[0]);
for (int i = 1; i < v.size(); ++i) {
if (cmp(arg(v[i].second - v[i].first) -
arg(v[i - 1].second - v[i - 1].first)) == 0) {
continue;
}
while (ans.size() > 0 && !satisfy(ans.back(), v[i])) {
ans.pop_back();
q.pop_back();
}
while (ans.size() > 0 && !satisfy(ans.front(), v[i])) {
ans.pop_front();
q.pop_front();
}
ans.push_back(crosspoint(q.back(), v[i]));
q.push_back(v[i]);
}
while (ans.size() > 0 && !satisfy(ans.back(), q.front())) {
ans.pop_back();
q.pop_back();
}
while (ans.size() > 0 && !satisfy(ans.front(), q.back())) {
ans.pop_front();
q.pop_front();
}
ans.push_back(crosspoint(q.back(), q.front()));
return vector<point>(ans.begin(), ans.end());
}
vector<point> convexIntersection(vector<point> v1, vector<point> v2) {
vector<pair<point, point> > h;
for (int i = 0; i < v1.size(); ++i)
h.push_back(pair<point, point>(v1[i], v1[(i + 1) % v1.size()]));
for (int i = 0; i < v2.size(); ++i)
h.push_back(pair<point, point>(v2[i], v2[(i + 1) % v2.size()]));
return HalfplaneIntersection(h);
}
int n;
point o, x;
int main() {
double mmax = 0, mmin = 1e9;
cin >> n >> o;
vector<point> v;
for (int i = 0; i < n; ++i) {
cin >> x;
mmax = max(dist(x, o), mmax);
mmin = min(dist(x, o), mmin);
v.push_back(x);
}
v.push_back(*v.begin());
for (int i = 0; i < v.size() - 1; ++i) {
point cp;
PointProjLine(o, v[i], v[i + 1], cp);
if (PointOnSegment(cp, v[i], v[i + 1]))
mmin = min(mmin, dis_point_segment(o, v[i], v[i + 1]));
}
printf("%.10f\n", (sqr(mmax) - sqr(mmin)) * pi);
}
|
#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 abs(a * x + b * y + c) / sqrt(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;
d = sqrt(dot(p - v[i], p - v[i]));
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 (is_inside(p, v[i], v[i + 1])) r = min(r, d);
}
cout << setprecision(13) << fixed << PI * (rr * rr - r * r) << "\n\n";
}
}
|
#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 = (a[i - 1].x - x) * (a[i].y - y) - (a[i - 1].y - y) * (a[i].x - x);
k2 = fabs(k2);
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 double PI =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481;
int n, i;
long double CAN, xp, yp, MN, MX, big, small;
long double x[1001000], y[1001000];
bool good_triangle(long double x1, long double fdkjfsdkfs, long double x2,
long double y2, long double x3, long double y3) {
long double A = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3);
long double B = (x1 - x2) * (x1 - x2) + (fdkjfsdkfs - y2) * (fdkjfsdkfs - y2);
long double C = (x1 - x3) * (x1 - x3) + (fdkjfsdkfs - y3) * (fdkjfsdkfs - y3);
return (A + B >= C && A + C >= B);
}
long double prod(long double x1, long double fdkjfsdkfs, long double x2,
long double y2) {
long double ret = x1 * y2 - fdkjfsdkfs * x2;
if (ret < 0) ret = -ret;
return ret;
}
int main() {
ios_base::sync_with_stdio(0);
cout.precision(10);
cin >> n >> xp >> yp;
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
MX = -9e18;
MN = 9e18;
for (int i = 1; i <= n; i++) {
MX = max(MX, hypot(x[i] - xp, y[i] - yp));
MN = min(MN, hypot(x[i] - xp, y[i] - yp));
}
big = PI * MX * MX;
x[0] = x[n];
y[0] = y[n];
x[n + 1] = x[1];
y[n + 1] = y[1];
for (int i = 1; i <= n; i++) {
if (good_triangle(xp, yp, x[i], y[i], x[i + 1], y[i + 1])) {
x[i] -= xp;
y[i] -= yp;
x[i + 1] -= xp;
y[i + 1] -= yp;
CAN = prod(x[i], y[i], x[i + 1], y[i + 1]) /
hypot(x[i] - x[i + 1], y[i] - y[i + 1]);
x[i] += xp;
y[i] += yp;
x[i + 1] += xp;
y[i + 1] += yp;
MN = min(MN, CAN);
}
}
small = PI * MN * MN;
cout << fixed << big - small << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
int n;
long double x[MAX], y[MAX], ma = 0, mi = 1e17, xx, yy;
long double dis(long double x1, long double y1, long double x2 = xx,
long double y2 = yy) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
long double f(long double x1, long double y1, long double x2, long double y2) {
for (int i = 0; i < 60; i++) {
long double mx1 = (x2 - x1) / 3.0 + x1, mx2 = (x2 - x1) / 3.0 * 2 + x1,
my1 = (y2 - y1) / 3.0 + y1, my2 = (y2 - y1) / 3.0 * 2 + y1;
if (dis(mx1, my1) < dis(mx2, my2))
x2 = mx2, y2 = my2;
else
x1 = mx1, y1 = my1;
}
return dis(x1, y1);
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> xx >> yy;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i], ma = max(ma, dis(x[i], y[i], xx, yy));
if (i) mi = min(mi, f(x[i], y[i], x[i - 1], y[i - 1]));
}
mi = min(mi, f(x[n - 1], y[n - 1], x[0], y[0]));
cout << fixed << setprecision(9) << (ma * ma - mi * mi) * acos(0) * 2;
}
|
#include <bits/stdc++.h>
using namespace std;
long double ax[100010], by[100010];
long double x, y;
int n;
long double calc(long double t, int it) {
long double xx = ax[it] * t + ax[it - 1] * (1 - t);
long double yy = by[it] * t + by[it - 1] * (1 - t);
return xx * xx + yy * yy;
}
long double dist(int it) {
long double cur = ax[it] * ax[it] + by[it] * by[it];
if (it) {
it--;
cur = min(cur, ax[it] * ax[it] + by[it] * by[it]);
++it;
} else
return cur;
long double l = 0.0, r = 1.0;
int IT = 50;
while (IT--) {
double m1 = l + (r - l) / 3.0;
double m2 = l + 2.0 / 3.0 * (r - l);
if (calc(m1, it) > calc(m2, it)) {
l = m1;
} else
r = m2;
}
return min(calc(l, it), cur);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios::fixed);
cout.precision(10);
cin >> n;
cin >> x >> y;
long double mind = 1e18, maxd = 0;
for (int i = 0; i < n; ++i) {
long double a, b;
cin >> a >> b;
ax[i] = (a -= x);
by[i] = (b -= y);
mind = min(mind, dist(i));
maxd = max(maxd, a * a + b * b);
}
ax[n] = ax[0];
by[n] = by[0];
mind = min(mind, dist(n));
cout << 4 * atan(1) * (maxd - mind) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
struct node {
double x;
double y;
} arr[1001000];
int n;
double MAX = 0, MIN = 100000000;
double dis(node a, node b) {
double x = a.x - b.x;
double y = a.y - b.y;
return sqrt(x * x + y * y);
}
int main() {
cin >> n >> arr[0].x >> arr[0].y;
for (int i = 1; i <= n; i++) {
cin >> arr[i].x >> arr[i].y;
}
for (int i = 1; i <= n; i++) {
MAX = max(MAX, dis(arr[0], arr[i]));
}
arr[n + 1] = arr[1];
for (int i = 1; i <= n; i++) {
double bian1 = dis(arr[i], arr[0]);
double bian2 = dis(arr[i + 1], arr[0]);
double bian3 = dis(arr[i], arr[i + 1]);
if (bian1 * bian1 >= bian2 * bian2 + bian3 * bian3)
MIN = min(MIN, bian2);
else if (bian2 * bian2 >= bian1 * bian1 + bian3 * bian3)
MIN = min(MIN, bian1);
else {
double p = (bian1 + bian2 + bian3) / 2.0;
double s = sqrt(p * (p - bian1) * (p - bian2) * (p - bian3));
double h = 2 * s / bian3;
MIN = min(MIN, h);
}
}
double ans = ((MAX * MAX) - (MIN * MIN)) * acos(-1.0);
printf("%.7lf", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
long long n, a, b, x[100010], y[100010];
int main() {
ios::sync_with_stdio(0);
cin >> n >> a >> b;
double mn = 1e18, mx = 0;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
double dx = x[i] - a;
double dy = y[i] - b;
double d = dx * dx + dy * dy;
mn = min(mn, d);
mx = max(mx, d);
}
x[n] = x[0];
y[n] = y[0];
for (int i = 0; i < n; i++) {
if (x[i + 1] == x[i] && y[i + 1] == y[i]) continue;
double dx = x[i + 1] - x[i];
double dy = y[i + 1] - y[i];
double da = a - x[i];
double db = b - y[i];
double da2 = a - x[i + 1];
double db2 = b - y[i + 1];
double dot1 = dx * da + dy * db;
double dot2 = dx * da2 + dy * db2;
if (dot1 < 0 || dot2 > 0) continue;
double cross = dx * db - dy * da;
double d = abs(cross) / hypot(dx, dy);
mn = min(mn, d * d);
}
cout << fixed << setprecision(15) << (mx - mn) * PI << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
int size(const T &x) {
return x.size();
}
const int INF = 2147483647;
const double EPS = 1e-9;
const double pi = acos(-1.0);
double dot(const complex<double> &a, const complex<double> &b) {
return real(conj(a) * b);
}
double cross(const complex<double> &a, const complex<double> &b) {
return imag(conj(a) * b);
}
complex<double> rotate(const complex<double> &p, double radians = pi / 2,
const complex<double> &about = complex<double>(0, 0)) {
return (p - about) * exp(complex<double>(0, radians)) + about;
}
complex<double> reflect(const complex<double> &p, const complex<double> &about1,
const complex<double> &about2) {
complex<double> z = p - about1, w = about2 - about1;
return conj(z / w) * w + about1;
}
complex<double> proj(const complex<double> &u, const complex<double> &v) {
return dot(u, v) / dot(u, u) * u;
}
complex<double> normalize(const complex<double> &p, double k = 1.0) {
return abs(p) == 0 ? complex<double>(0, 0) : p / abs(p) * k;
}
double ccw(const complex<double> &a, const complex<double> &b,
const complex<double> &c) {
return cross(b - a, c - b);
}
bool collinear(const complex<double> &a, const complex<double> &b,
const complex<double> &c) {
return abs(ccw(a, b, c)) < EPS;
}
double angle(const complex<double> &a, const complex<double> &b,
const complex<double> &c) {
return acos(dot(b - a, c - b) / abs(b - a) / abs(c - b));
}
double signed_angle(const complex<double> &a, const complex<double> &b,
const complex<double> &c) {
return asin(cross(b - a, c - b) / abs(b - a) / abs(c - b));
}
double angle(const complex<double> &p) { return atan2(imag(p), real(p)); }
complex<double> perp(const complex<double> &p) {
return complex<double>(-imag(p), real(p));
}
double progress(const complex<double> &p, const complex<double> &a,
const complex<double> &b) {
if (abs(real(a) - real(b)) < EPS)
return (imag(p) - imag(a)) / (imag(b) - imag(a));
else
return (real(p) - real(a)) / (real(b) - real(a));
}
double polygon_area_signed(vector<complex<double> > p) {
double area = 0;
int cnt = size(p);
for (__typeof(1) i = (1); i < (cnt - 1); ++i)
area += cross(p[i] - p[0], p[i + 1] - p[0]);
return area / 2;
}
double polygon_area(vector<complex<double> > p) {
return abs(polygon_area_signed(p));
}
int point_in_polygon(vector<complex<double> > p, complex<double> q) {
int n = size(p);
bool in = false;
double d;
for (int i = 0, j = n - 1; i < n; j = i++)
if (collinear(p[i], q, p[j]) && 0 <= (d = progress(q, p[i], p[j])) &&
d <= 1)
return 0;
for (int i = 0, j = n - 1; i < n; j = i++)
if ((real(p[i]) < real(q) && real(q) <= real(p[j]) &&
ccw(p[i], p[j], q) < 0) ||
(real(p[j]) < real(q) && real(q) <= real(p[i]) &&
ccw(p[j], p[i], q) < 0))
in = !in;
return in ? -1 : 1;
}
bool collinear(const complex<double> &a, const complex<double> &b,
const complex<double> &p, const complex<double> &q) {
return abs(ccw(a, b, p)) < EPS && abs(ccw(a, b, q)) < EPS;
}
bool parallel(const complex<double> &a, const complex<double> &b,
const complex<double> &p, const complex<double> &q) {
return abs(cross(b - a, q - p)) < EPS;
}
complex<double> closest_point(const complex<double> &a,
const complex<double> &b,
const complex<double> &c, bool segment = false) {
if (segment) {
if (dot(b - a, c - b) > 0) return b;
if (dot(a - b, c - a) > 0) return a;
}
double t = dot(c - a, b - a) / norm(b - a);
return a + t * (b - a);
}
double line_segment_distance(const complex<double> &a, const complex<double> &b,
const complex<double> &c,
const complex<double> &d) {
double x = INFINITY;
if (abs(a - b) < EPS && abs(c - d) < EPS)
x = abs(a - c);
else if (abs(a - b) < EPS)
x = abs(a - closest_point(c, d, a, true));
else if (abs(c - d) < EPS)
x = abs(c - closest_point(a, b, c, true));
else if ((ccw(a, b, c) < 0) != (ccw(a, b, d) < 0) &&
(ccw(c, d, a) < 0) != (ccw(c, d, b) < 0))
x = 0;
else {
x = min(x, abs(a - closest_point(c, d, a, true)));
x = min(x, abs(b - closest_point(c, d, b, true)));
x = min(x, abs(c - closest_point(a, b, c, true)));
x = min(x, abs(d - closest_point(a, b, d, true)));
}
return x;
}
bool intersect(const complex<double> &a, const complex<double> &b,
const complex<double> &p, const complex<double> &q,
complex<double> &res, bool segment = false) {
complex<double> r = b - a, s = q - p;
double c = cross(r, s), t = cross(p - a, s) / c, u = cross(p - a, r) / c;
if (segment && (t < 0 - EPS || t > 1 + EPS || u < 0 - EPS || u > 1 + EPS))
return false;
res = a + t * r;
return true;
}
double area(double r) { return r * r * pi; }
int main() {
int n;
double x, y;
scanf("%d %lf %lf\n", &n, &x, &y);
complex<double> mid(x, y);
vector<complex<double> > P;
for (__typeof(0) i = (0); i < (n); ++i) {
double a, b;
scanf("%lf %lf", &a, &b);
P.push_back(complex<double>(a, b));
}
double mx = 0, mn = INFINITY;
for (__typeof(0) i = (0); i < (n); ++i) {
int j = (i + 1) % n;
mx = max(mx, abs(P[i] - mid));
complex<double> c = closest_point(P[i], P[j], mid, true);
mn = min(mn, abs(c - mid));
}
printf("%0.10lf\n", area(mx) - area(mn));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
T Bitcnt(T a) {
int sum = 0;
while (a) {
if (a & 1) sum++;
a /= 2;
}
return sum;
}
template <class T>
T Max3(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
T Lcm(T a, T b) {
T tmp = __gcd(a, b);
return (a / tmp) * b;
}
template <class T>
T Pow(T a, T b) {
T ans = 1;
T base = a;
while (b) {
if (b & 1) ans = (ans * base);
base = (base * base);
b /= 2;
}
return ans;
}
long long Bigmod(long long a, long long b) {
long long res = 1;
long long pw = a % 1000000007LL;
while (b > 0) {
if (b & 1) res = (res * pw) % 1000000007LL;
pw = (pw * pw) % 1000000007LL;
b /= 2;
}
return res;
}
int a_x[] = {1, -1, 0, 0};
int a_y[] = {0, 0, 1, -1};
long long X, Y;
void extend_euclid(long long a, long long b) {
if (b == 0) {
X = a;
Y = 0;
return;
}
extend_euclid(b, a % b);
long long x, y;
x = Y;
y = X - (a / b) * Y;
X = x;
Y = y;
}
long long inverse_modulo(long long a, long long b) {
extend_euclid(a, b);
return (X + 1000000007LL) % 1000000007LL;
}
double dist(double x1, double y1, pair<double, double> tmp) {
double t = 1LL * (x1 - tmp.first) * (x1 - tmp.first) +
1LL * (y1 - tmp.second) * (y1 - tmp.second);
return (t);
}
int n;
pair<int, int> inp[200005];
double dist1(int indx1, int indx2, int x, int y) {
double lx, ly, rx, ry, ltx, lty, rtx, rty;
lx = inp[indx1].first;
ly = inp[indx1].second;
rx = inp[indx2].first;
ry = inp[indx2].second;
int tot = 100;
double ans = (long long)1e18;
while (tot--) {
ltx = (lx * 2 + rx) / 3.0;
lty = (ly * 2 + ry) / 3.0;
rtx = (lx + rx * 2) / 3.0;
rty = (ly + ry * 2) / 3.0;
if (dist(ltx, lty, make_pair(x, y)) - dist(rtx, rty, make_pair(x, y)) <
1e-13) {
rx = rtx;
ry = rty;
ans = min(ans, dist(ltx, lty, make_pair(x * 1.0, y * 1.0)));
} else {
lx = ltx;
ly = lty;
ans = min(ans, dist(rtx, rty, make_pair(x * 1.0, y * 1.0)));
}
}
return ans;
}
double dist2(int indx1, int indx2, int x, int y) {
double lx, ly, rx, ry, ltx, lty, rtx, rty;
lx = inp[indx1].first;
ly = inp[indx1].second;
rx = inp[indx2].first;
ry = inp[indx2].second;
int tot = 100;
double ans = 0.0;
while (tot--) {
ltx = (lx * 2 + rx) / 3.0;
lty = (ly * 2 + ry) / 3.0;
rtx = (lx + rx * 2) / 3.0;
rty = (ly + ry * 2) / 3.0;
if (dist(ltx, lty, make_pair(x, y)) - dist(rtx, rty, make_pair(x, y)) >
1e-13) {
rx = rtx;
ry = rty;
ans = max(ans, dist(ltx, lty, make_pair(x * 1.0, y * 1.0)));
} else {
lx = ltx;
ly = lty;
ans = max(ans, dist(rtx, rty, make_pair(x * 1.0, y * 1.0)));
}
}
return ans;
}
int main() {
int n;
scanf("%d", &n);
double mx = 0.0;
double mn = (long long)1e18;
int x, y;
scanf("%d %d", &x, &y);
for (int i = 0; i <= n - 1; i++) {
int a, b;
scanf("%d %d", &a, &b);
inp[i] = make_pair(a, b);
}
for (int i = 0; i <= n - 1; i++) {
int f = i;
int s = (i + 1) % n;
double res = dist1(f, s, x, y);
mn = min(res, mn);
res = dist2(f, s, x, y);
mx = max(res, mx);
}
double ans;
ans = acos(-1.0) * (mx - mn);
printf("%.12lf\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
class dot {
public:
dot() {
x = 0;
y = 0;
}
dot(long long x, long long y) {
this->x = x;
this->y = y;
}
long long x;
long long y;
};
long double dist(dot dot1, dot dot2) {
return std::sqrt((long double)((dot1.x - dot2.x) * (dot1.x - dot2.x) +
(dot1.y - dot2.y) * (dot1.y - dot2.y)));
}
long double scalar_mul(dot a, dot b, dot p) {
return (b.x - a.x) * (p.x - a.x) + (b.y - a.y) * (p.y - a.y);
}
long double dot_segment_dist(dot p, dot a, dot b) {
long long aa = b.y - a.y, bb = a.x - b.x, cc = a.y * b.x - a.x * b.y;
if (scalar_mul(a, b, p) > 0 && scalar_mul(b, a, p) > 0) {
return std::abs((aa * p.x + bb * p.y + cc)) / std::sqrt(aa * aa + bb * bb);
} else {
return min(dist(a, p), dist(b, p));
}
}
int main() {
ios_base::sync_with_stdio(false);
int n;
dot p;
cin >> n >> p.x >> p.y;
dot fst;
cin >> fst.x >> fst.y;
long double mmax = dist(fst, p);
long double mmin = dist(fst, p);
dot prev = fst, tmp;
for (int i = 1; i < n; i++) {
cin >> tmp.x >> tmp.y;
mmax = max(mmax, dist(tmp, p));
mmin = min(mmin, dot_segment_dist(p, prev, tmp));
prev = tmp;
}
mmin = min(mmin, dot_segment_dist(p, fst, tmp));
long double sq = (3.14159265358979323846) * (mmax * mmax - mmin * mmin);
cout << fixed << setprecision(10);
cout << sq << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, PX, PY, prevX, prevY, X, Y, firstX, firstY;
double valMin = 1e20, valMax = -1;
double dist(double x1, double y1, double x2, double y2) {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
double dist2(double x1, double y1, double x2, double y2) {
double m, A, B, C;
m = (double)(y1 - y2) / (x1 - x2);
if (abs(m) == INFINITY) {
B = 0;
A = 1;
C = -x1;
} else {
B = 1, A = -m, C = -y1 + m * x1;
}
double interX = (B * (B * PX - A * PY) - A * C) / (A * A + B * B);
double interY = (A * (-B * PX + A * PY) - B * C) / (A * A + B * B);
if (interX - max(x1, x2) <= 1e-9 && interX - min(x1, x2) >= -1e-9 &&
interY - max(y1, y2) <= 1e-9 && interY - min(y1, y2) >= -1e-9) {
return pow(abs(A * PX + B * PY + C) / sqrt(A * A + B * B), 2);
}
return 1e20;
}
int main() {
scanf("%d%d%d", &N, &PX, &PY);
scanf("%d%d", &firstX, &firstY);
prevX = firstX, prevY = firstY;
valMin = dist(prevX, prevY, PX, PY);
valMax = valMin;
N--;
while (N--) {
scanf("%d%d", &X, &Y);
valMax = max(valMax, dist(X, Y, PX, PY));
valMin = min(valMin, dist(X, Y, PX, PY));
valMin = min(valMin, dist2(X, Y, prevX, prevY));
prevX = X, prevY = Y;
}
valMin = min(valMin, dist2(firstX, firstY, X, Y));
printf("%.8lf\n", 3.141592653589793238446264338327950288419716939937510582 *
(valMax - valMin));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using point = complex<long long>;
long long cross(point a, point b) {
return a.real() * b.imag() - a.imag() * b.real();
}
long long dot(point a, point b) {
return a.real() * b.real() + a.imag() * b.imag();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(8);
int n, px, py;
cin >> n >> px >> py;
point p = point(px, py);
double maxi = 0.0, mini = HUGE_VAL;
vector<point> polygon(n);
for (auto &v : polygon) {
int x, y;
cin >> x >> y;
v = point(x, y);
maxi = max(maxi, M_PI * norm(v - p));
}
for (int i = 0; i < n; ++i) {
int j = (i + 1) % n;
point a = polygon[i], b = polygon[j];
point v = a - b;
if ((dot(v, a) < dot(v, p)) == (dot(v, p) < dot(v, b))) {
mini = min(mini, M_PI * cross(v, p - b) * cross(v, p - b) / norm(v));
} else {
mini = min(mini, M_PI * min(norm(a - p), norm(b - p)));
}
}
cout << maxi - mini << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1);
const int mod = 100000000;
double max(double a, double b) { return a > b ? a : b; };
double min(double a, double b) { return a < b ? a : b; };
const int max_ = 100000;
struct Point {
double x, y;
Point(double xx, double yy) : x(xx), y(yy) {}
Point(){};
} p[max_ + 5];
Point o;
Point operator-(Point a, Point c) { return Point(a.x - c.x, a.y - c.y); }
int n;
double Dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
double dist(Point a, Point b) { return sqrt(Dot(a - b, a - b)); }
double Cross(Point a, Point b) { return fabs(a.x * b.y - b.x * a.y); }
double Pointtoline(Point o, Point a, Point b) {
return Cross(o - a, b - a) / dist(a, b);
}
double Pointtosegment(Point o, Point a, Point b) {
if (Dot(o - a, b - a) < 0)
return dist(o, a);
else if (Dot(o - b, a - b) < 0)
return dist(o, b);
else
return Pointtoline(o, a, b);
}
int main() {
while (~scanf("%d %lf %lf", &n, &o.x, &o.y)) {
double minn = inf, maxn = 0;
for (int i = 0; i < n; i++) scanf("%lf %lf", &p[i].x, &p[i].y);
p[n] = p[0];
for (int i = 0; i < n; i++) {
double temp = Pointtosegment(o, p[i], p[i + 1]);
minn = min(minn, temp);
maxn = max(maxn, dist(p[i], o));
}
printf("%.18f\n", pi * (maxn * maxn - minn * minn));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pai = 3.14159265;
struct node {
double x, y;
} ver[100010];
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
double PointToSegDist(double x, double y, double x1, double y1, double x2,
double y2) {
double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
if (cross <= 0) return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
double d2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
if (cross >= d2) return sqrt((x - x2) * (x - x2) + (y - y2) * (y - y2));
double r = cross / d2;
double px = x1 + (x2 - x1) * r;
double py = y1 + (y2 - y1) * r;
return sqrt((x - px) * (x - px) + (y - py) * (y - py));
}
int main() {
double x, y, maxlen, minlen, area;
int n, i;
scanf("%d %lf %lf", &n, &x, &y);
maxlen = 0;
minlen = 999999999;
for (i = 0; i < n; i++) {
scanf("%lf %lf", &ver[i].x, &ver[i].y);
maxlen = max(maxlen, dist(x, y, ver[i].x, ver[i].y));
}
minlen = min(minlen, PointToSegDist(x, y, ver[0].x, ver[0].y, ver[n - 1].x,
ver[n - 1].y));
for (i = 1; i < n; i++)
minlen = min(minlen, PointToSegDist(x, y, ver[i].x, ver[i].y, ver[i - 1].x,
ver[i - 1].y));
area = maxlen * maxlen * pai - minlen * minlen * pai;
printf("%lf\n", area);
}
|
#include <bits/stdc++.h>
using namespace std;
struct POINT {
double x, y;
double dis;
} xx[2000001], ind;
int n;
double x0, y666, x, y, ans, mii = 1e50, maxi;
double sqr(double k) { return k * k; }
double times(double x1, double y1, double x2, double y2) {
return fabs(x2 * y1 - x1 * y2) / 2.0;
}
int main() {
cin >> n;
cin >> x0 >> y666;
for (int i = 1; i <= n; i++) {
scanf("%lf %lf", &x, &y);
xx[i].x = x;
xx[i].y = y;
xx[i].dis = sqrt(sqr(x - x0) + sqr(y - y666));
mii = min(mii, xx[i].dis);
maxi = max(maxi, xx[i].dis);
}
xx[n + 1] = xx[1];
for (int i = 1; i <= n; i++) {
double x1 = xx[i].x, x2 = xx[i + 1].x, y1 = xx[i].y, y2 = xx[i + 1].y;
double d1 = xx[i].dis, d2 = xx[i + 1].dis;
if (d1 < d2) swap(d1, d2);
double d = sqrt(sqr(x1 - x2) + sqr(y1 - y2));
if (sqr(d1) > sqr(d2) + sqr(d) + 1e-8) continue;
double h = times(x1 - x0, y1 - y666, x2 - x0, y2 - y666) / d * 2.0;
mii = min(mii, h);
maxi = max(maxi, h);
}
ans = (acos(-1) * sqr(maxi) - acos(-1) * sqr(mii));
printf("%.12lf", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
struct Node {
Node() {}
Node(double a, double b) {
x = a;
y = b;
}
double x, y;
};
Node node[100005];
double dis(Node a, Node b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
double get_dis(Node &a, Node &b, Node &c) {
double k1 = dis(a, b), k2 = dis(a, c), k3 = dis(b, c);
if (k1 >= k2 + k3) return k2;
if (k2 >= k1 + k3) return k1;
double d = fabs((b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x));
return d * d / k3;
}
int main() {
int n;
double x, y;
double maxs = 0, mins = 1e18;
Node o;
scanf("%d%lf%lf", &n, &o.x, &o.y);
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &node[i].x, &node[i].y);
maxs = max(maxs, dis(o, node[i]));
}
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
mins = min(mins, get_dis(o, node[i], node[j]));
}
double ans = (maxs - mins) * acos(-1);
printf("%.18lf\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
void chmin(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
int n;
double px, py;
double X[100100], Y[100100];
double ABS(double x) { return (x >= 0) ? x : -x; }
double Angle(double ax, double ay, double bx, double by) {
double dot = ax * bx + ay * by;
double sza = sqrt(((ax) * (ax)) + ((ay) * (ay)));
double szb = sqrt(((bx) * (bx)) + ((by) * (by)));
double c = (dot / sza) / szb;
return c;
}
double len(int j) {
int a = j, b = (j + 1) % n;
double A = Y[b] - Y[a];
double B = X[a] - X[b];
double C = Y[a] * X[b] - X[a] * Y[b];
double D = ABS(A * px + B * py + C) / sqrt(((A) * (A)) + ((B) * (B)));
if (Angle(px - X[a], py - Y[a], X[b] - X[a], Y[b] - Y[a]) < 0) return -1.0;
if (Angle(px - X[b], py - Y[b], X[a] - X[b], Y[a] - Y[b]) < 0) return -1.0;
return D;
}
double len2(int j) {
return sqrt(((X[j] - px) * (X[j] - px)) + ((Y[j] - py) * (Y[j] - py)));
}
int main() {
scanf("%d %lf %lf", &n, &px, &py);
for (int i = 0; i < n; i++) {
scanf("%lf %lf", &X[i], &Y[i]);
}
double r = 100000000000000.0, R = -1.0;
for (int i = 0; i < n; i++) {
double dist = len(i);
if (dist >= 0) {
r = min(r, dist);
R = max(R, dist);
}
dist = len2(i);
r = min(r, dist);
R = max(R, dist);
}
printf("%.16f\n", (((R) * (R)) - ((r) * (r))) * M_PI);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1e5 + 123;
const double PI = 3.14159265358979323846264338;
const double eps = 1e-9;
struct point {
double x, y;
};
double dist(point a, point b) { return hypot(a.x - b.x, a.y - b.y); }
double dot(point a, point b) { return a.x * b.x + a.y * b.y; }
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
point p;
vector<point> v(n);
cin >> p.x >> p.y;
point mx = p, mn = {100000000000000, 1};
for (int i = 0; i < n; i++) {
cin >> v[i].x >> v[i].y;
}
double R = -1e18, r = 1e18;
for (int i = 0; i < n; i++) {
point q = v[i], w = v[(i + 1) % n];
double a, b, c;
a = q.y - w.y;
b = w.x - q.x;
c = -(a * q.x + b * q.y);
double d;
d = fabs(a * p.x + b * p.y + c) / hypot(a, b);
double M = max(dist(q, p), dist(w, p));
r = min(r, min(dist(q, p), dist(w, p)));
R = max(R, M);
point v1, v2, v3, v4;
v1 = {p.x - q.x, p.y - q.y};
v2 = {w.x - q.x, w.y - q.y};
swap(q, w);
v3 = {p.x - q.x, p.y - q.y};
v4 = {w.x - q.x, w.y - q.y};
if (dot(v1, v2) > 0 && dot(v3, v4) > 0) {
r = min(r, d);
}
}
double s1, s2;
s1 = PI * R * R;
s2 = PI * r * r;
cout << fixed << setprecision(11);
cout << s1 - s2;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct Vector {
double x, y;
Vector() {}
Vector(double x, double y) : x(x), y(y) {}
Vector(Vector const &v) : x(v.x), y(v.y) {}
Vector(Vector const &a, Vector const &b) : x(b.x - a.x), y(b.y - a.y) {}
double length() const { return sqrt(x * x + y * y); }
Vector norm() const {
double len = length();
return Vector(x / len, y / len);
}
Vector operator*(double c) const { return Vector(x * c, y * c); }
};
struct Line {
double a, b, c;
Line(Vector const &x, Vector const &y) {
a = y.y - x.y;
b = x.x - y.x;
c = -(a * x.x + b * x.y);
}
Vector norm() const { return Vector(a, b); }
Vector perp(Vector const &v) {
Vector n = norm().norm();
double dist = (a * v.x + b * v.y + c) / sqrt(a * a + b * b);
Vector to = n * dist;
return Vector(v.x - to.x, v.y - to.y);
}
};
bool on(Vector const &a, Vector const &b, Vector const &p) {
return ((a.x <= p.x && b.x >= p.x) || (a.x >= p.x && b.x <= p.x)) &&
((a.y <= p.y && b.y >= p.y) || (a.y >= p.y && b.y <= p.y));
}
int main() {
int n;
Vector c;
cin >> n >> c.x >> c.y;
vector<Vector> v(n);
double min_dist = 1e20, max_dist = 0;
for (int i = 0; i != n; ++i) {
cin >> v[i].x >> v[i].y;
double dist = Vector(v[i], c).length();
min_dist = min(min_dist, dist);
max_dist = max(max_dist, dist);
}
for (int i = 0; i != n; ++i) {
int next = (i + 1) % n;
Line l(v[i], v[next]);
Vector p = l.perp(c);
if (!on(v[i], v[next], p)) continue;
double dist = Vector(p, c).length();
min_dist = min(min_dist, dist);
max_dist = max(max_dist, dist);
}
cout.precision(30);
cout << fixed
<< 3.14159265358979323846L * (max_dist * max_dist - min_dist * min_dist)
<< '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline void scanint(int &x) {
register int c = 0;
x = 0;
int flag = 0;
for (; ((c != 45) && (c < 48 || c > 57)); c = getchar())
;
for (; ((c == 45) || (c > 47 && c < 58)); c = getchar()) {
if (c == 45)
flag = 1;
else
x = (x << 1) + (x << 3) + c - 48;
}
if (flag) x = -x;
}
double dist(double x1, double x2, double y1, double y2) {
return ((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
struct point {
double x, y;
} p[100005];
double xx, yy;
double fun(point p1, point p2) {
double t1 =
abs((p2.y - p1.y) * xx - (p2.x - p1.x) * yy + p2.x * p1.y - p2.y * p1.x);
double t2 = ((p2.y - p1.y) * (p2.y - p1.y) + (p2.x - p1.x) * (p2.x - p1.x));
return (t1 * t1) / t2;
}
bool angle(point p1, point p2) {
double a = dist(p2.x, p1.x, p2.y, p1.y);
double b = dist(p2.x, xx, p2.y, yy);
double c = dist(xx, p1.x, yy, p1.y);
return (b * b < a * a + c * c);
}
int main() {
int n, j, i;
scanf("%d", &n);
cin >> xx >> yy;
double minn = 999999999999999999.0;
double maxx = 0;
for (i = 0; i < n; i++) {
cin >> p[i].x;
cin >> p[i].y;
minn = min(minn, dist(xx, p[i].x, yy, p[i].y));
maxx = max(maxx, dist(xx, p[i].x, yy, p[i].y));
}
for (i = 0; i < n; i++) {
j = (i + 1) % n;
if (angle(p[i], p[j]) && angle(p[j], p[i])) {
minn = min(minn, fun(p[i], p[j]));
}
}
double an = (acos(-1) * maxx) - (acos(-1) * minn);
printf("%0.10lf\n", an);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long oo = 10000000000000000ll;
const int N = 1000009;
int n;
pair<long long, long long> P, a[N];
long long vmax, vmin;
bool check(pair<long long, long long> i, pair<long long, long long> j,
pair<long long, long long> P) {
long long a, b, c;
a = j.first - i.first;
b = j.second - i.second;
c = -a * P.first - b * P.second;
long long k1 = (a * i.first + b * i.second + c);
long long k2 = (a * j.first + b * j.second + c);
if ((k1 > 0 && k2 < 0) || (k1 < 0 && k2 > 0))
return 1;
else
return 0;
}
long long dis_sq(pair<long long, long long> i, pair<long long, long long> j) {
return ((i.first - j.first) * (i.first - j.first) +
(i.second - j.second) * (i.second - j.second));
}
double dis_line(pair<long long, long long> i, pair<long long, long long> j,
pair<long long, long long> P) {
double a, b, c;
a = j.second - i.second;
b = i.first - j.first;
c = -a * i.first - b * i.second;
return ((double)((a * (double)P.first + b * (double)P.second + c) /
(a * a + b * b))) *
(a * (double)P.first + b * (double)P.second + c);
}
double PI = 3.1415926535897932384626433832795;
int main() {
vmax = 0;
vmin = oo;
cin >> n >> P.first >> P.second;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
long long kk = dis_sq(P, a[i]);
vmax = max(vmax, kk);
vmin = min(vmin, kk);
}
a[n + 1] = a[1];
double vm = vmax, vn = vmin;
for (int i = 1; i <= n; i++)
if (check(a[i], a[i + 1], P)) {
double kk = dis_line(a[i], a[i + 1], P);
vm = max(vm, kk);
vn = min(vn, kk);
}
double ans = vm - vn;
printf("%0.15f", ans * PI);
}
|
#include <bits/stdc++.h>
using namespace std;
struct node {
double x;
double y;
} arr[1001000];
int n;
double MAX = 0, MIN = 100000000;
double dis(node a, node b) {
double x = a.x - b.x;
double y = a.y - b.y;
return sqrt(x * x + y * y);
}
int main() {
cin >> n >> arr[0].x >> arr[0].y;
for (int i = 1; i <= n; i++) {
cin >> arr[i].x >> arr[i].y;
}
for (int i = 1; i <= n; i++) {
MAX = max(MAX, dis(arr[0], arr[i]));
}
arr[n + 1] = arr[1];
for (int i = 1; i <= n; i++) {
double bian1 = dis(arr[i], arr[0]);
double bian2 = dis(arr[i + 1], arr[0]);
double bian3 = dis(arr[i], arr[i + 1]);
if (bian1 * bian1 >= bian2 * bian2 + bian3 * bian3)
MIN = min(MIN, bian2);
else if (bian2 * bian2 >= bian1 * bian1 + bian3 * bian3)
MIN = min(MIN, bian1);
else {
double p = (bian1 + bian2 + bian3) / 2.0;
double s = sqrt(p * (p - bian1) * (p - bian2) * (p - bian3));
double h = 2 * s / bian3;
MIN = min(MIN, h);
}
}
double ans = ((MAX * MAX) - (MIN * MIN)) * acos(-1.0);
printf("%.7lf", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline double dist(double a, double b, double c, double d) {
return (a - c) * (a - c) + (b - d) * (b - d);
}
inline double j(double k1, double b1, double k2, double b2) {
return (double)(b2 - b1) / (k1 - k2);
}
double dist2(double a, double b, double c1, double d1, double c, double d) {
if (c == c1) {
if (b <= d1 && b >= d) {
return (c - a) * (c - a);
} else if (b <= d && b >= d1) {
return (c - a) * (c - a);
} else {
return min(dist(a, b, c, d), dist(a, b, c1, d1));
}
}
if (d == d1) {
if (a <= c1 && a >= c) {
return (d - b) * (d - b);
} else if (a <= c && a >= c1) {
return (d - b) * (d - b);
} else {
return min(dist(a, b, c, d), dist(a, b, c1, d1));
}
}
double k1 = ((double)d - d1) / ((double)c - c1);
double k2 = -1 / k1;
double b1 = (double)d - (c * k1);
double b2 = (double)b - (a * k2);
double x = j(k1, b1, k2, b2);
if (x > c1 && x > c) {
return min(dist(a, b, c, d), dist(a, b, c1, d1));
}
if (x < c1 && x < c) {
return min(dist(a, b, c, d), dist(a, b, c1, d1));
}
return dist(a, b, x, k1 * x + b1);
}
int main() {
int n;
double a, b, c, d, c1, d1, c2, d2, min1, max1;
cin >> n >> a >> b;
cin >> c >> d;
c2 = c;
d2 = d;
min1 = max1 = (dist(a, b, c, d));
for (int i = 2; i <= n; i++) {
c1 = c;
d1 = d;
cin >> c >> d;
double dis = dist2(a, b, c1, d1, c, d);
if (min1 > dis) min1 = dis;
dis = dist(a, b, c, d);
if (max1 < dis) max1 = dis;
}
double dis = dist2(a, b, c2, d2, c, d);
if (min1 > dis) min1 = dis;
dis = dist(a, b, c, d);
if (max1 < dis) max1 = dis;
cout << setprecision(12) << 3.141592653589793 * (max1 - min1);
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
pair<long long, long long> P, d[100000];
double rm, rM;
int main() {
scanf("%d%I64d%I64d", &n, &P.first, &P.second);
for (int i = 0; i < n; i++) {
pair<long long, long long> Q;
scanf("%I64d%I64d", &Q.first, &Q.second);
double t = (P.first - Q.first) * (P.first - Q.first) +
(P.second - Q.second) * (P.second - Q.second);
if (i == 0)
rm = rM = t;
else {
if (rm > t) rm = t;
if (rM < t) rM = t;
}
d[i] = Q;
}
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
pair<long long, long long> Q =
make_pair(d[j].first - d[i].first, d[j].second - d[i].second);
double t =
Q.first * (P.first - d[i].first) + Q.second * (P.second - d[i].second);
t /= (Q.first * Q.first + Q.second * Q.second);
if (0 <= t && t <= 1) {
long long a = d[j].second - d[i].second;
long long b = -(d[j].first - d[i].first);
long long c = -(a * d[i].first + b * d[i].second);
double t = (a * P.first + b * P.second + c);
t = t * t / (a * a + b * b);
if (t < rm) rm = t;
}
}
double r = rM - rm;
printf("%.9f\n", r * 3.1415926535897932384626433832795);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct p {
double x, y;
} a[100005];
double x, y;
double juli(double xx1, double yy1, double xx2, double yy2) {
double xx0 = x, yy0 = y;
double temp, temp2;
temp = sqrt((xx2 - xx1) * (xx2 - xx1) + (yy2 - yy1) * (yy2 - yy1));
temp2 = (xx1 - xx0) * (yy2 - yy0) - (yy1 - yy0) * (xx2 - xx0);
temp2 = fabs(temp2);
return (temp2 / temp);
}
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;
r = min(r, juli(a[i].x, a[i].y, a[i - 1].x, a[i - 1].y));
}
printf("%.15lf\n", (R * R - r * r) * acos(-1.0));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
double pi = 3.141592653589793238462643383279;
int n;
double a, b;
cin >> n >> a >> b;
double x[n], y[n];
double u = 0, v = 1000000000000;
for (int i = 0; i < n; ++i) {
cin >> x[i] >> y[i];
}
double m, f;
for (int i = 0; i < n; ++i) {
if ((x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b) > u)
u = (x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b);
int l = i, r = (i + 1) % n;
if (x[l] != x[r]) {
m = (y[r] - y[l]) / (x[r] - x[l]);
f = ((m * (a - x[l]) + y[l] - b) * (m * (a - x[l]) + y[l] - b)) /
(m * m + 1);
if ((m * (y[r] - b) + (x[r] - a)) * (m * (y[l] - b) + (x[l] - a)) < 0)
v = min(v, f);
else
v = min(v, min(((x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b)),
((x[r] - a) * (x[r] - a) + (y[r] - b) * (y[r] - b))));
} else {
f = (x[l] - a) * (x[l] - a);
v = min(v, f);
}
}
u = pi * (u - v);
printf("%0.8f\n", u);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long cross(long long x1, long long y1, long long x2, long long y2) {
return x1 * y2 - x2 * y1;
}
long long sq(long long x) { return x * x; }
long double sq(long double x) { return x * x; }
long double dist(long long x, long long y, long long x1, long long y1) {
return sqrt(sq(x - x1) + sq(y - y1));
}
long double dist(long long x, long long y, long long x1, long long y1,
long long x2, long long y2) {
long long a = y2 - y1;
long long b = x1 - x2;
long long c = y1 * (x2 - x1) - x1 * (y2 - y1);
if ((x - x1) * (x2 - x1) + (y - y1) * (y2 - y1) < 0)
return sqrt(sq(x - x1) + sq(y - y1));
else if ((x - x2) * (x1 - x2) + (y - y2) * (y1 - y2) < 0)
return sqrt(sq(x - x2) + sq(y - y2));
else
return abs(a * x + b * y + c) / sqrt(a * a + b * b);
}
int main() {
int n, px, py;
cin >> n >> px >> py;
int x[n + 1], y[n + 1];
for (int k = 0; k < n; k++) cin >> x[k] >> y[k];
x[n] = x[0];
y[n] = y[0];
long double max_dist = -1, min_dist = 2e18;
for (int k = 0; k < n; k++) {
max_dist = max(max_dist, dist(px, py, x[k], y[k]));
min_dist = min(min_dist, dist(px, py, x[k], y[k], x[k + 1], y[k + 1]));
}
cout << fixed << setprecision(10);
cout << acos(-1.0) * (sq(max_dist) - sq(min_dist)) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000004;
double x[N], y[N];
int main() {
double pi = 3.141592653589793238462643383279;
int n;
double a, b;
scanf("%d %lf %lf", &n, &a, &b);
double u = 0.0, v = 1000000000000.0;
for (int i = 0; i < n; ++i) scanf("%lf %lf", &x[i], &y[i]);
double m, f;
for (int i = 0; i < n; ++i) {
if ((x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b) > u)
u = (x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b);
int l = i, r = (i + 1) % n;
if (x[l] != x[r]) {
m = (y[r] - y[l]) / (x[r] - x[l]);
f = ((m * (a - x[l]) + y[l] - b) * (m * (a - x[l]) + y[l] - b)) /
(m * m + 1);
if ((m * (y[r] - b) + (x[r] - a)) * (m * (y[l] - b) + (x[l] - a)) < 0)
v = min(v, f);
else
v = min(v, min(((x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b)),
((x[r] - a) * (x[r] - a) + (y[r] - b) * (y[r] - b))));
} else {
f = (x[l] - a) * (x[l] - a);
v = min(v, f);
}
}
u = pi * (u - v);
printf("%0.12f\n", u);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double phi = acos(-1.00);
const double eps = 1e-19;
struct node {
double x, y;
} p, poin[100005];
double dist(node a) {
return ((p.x - a.x) * (p.x - a.x) + (p.y - a.y) * (p.y - a.y));
}
int main() {
int n;
double lingkaranbesar = 0, lingkarankecil = (1 << 30);
scanf("%d%lf%lf", &n, &p.x, &p.y);
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &poin[i].x, &poin[i].y);
lingkaranbesar = max(lingkaranbesar, sqrt(dist(poin[i])));
}
for (int i = 0; i < n; i++) {
double lx = poin[i].x;
double ly = poin[i].y;
double rx = poin[(i + 1) % n].x;
double ry = poin[(i + 1) % n].y;
double m1, m2;
node mid1, mid2;
for (int i = 0; i < 100; i++) {
mid1.x = (2.0 * lx + rx) / 3.0;
mid1.y = (2.0 * ly + ry) / 3.0;
mid2.x = (lx + 2.0 * rx) / 3.0;
mid2.y = (ly + 2.0 * ry) / 3.0;
m1 = sqrt(dist(mid1));
m2 = sqrt(dist(mid2));
if (m1 - m2 < eps) {
rx = mid2.x;
ry = mid2.y;
} else {
lx = mid1.x;
ly = mid1.y;
}
}
if (lingkarankecil - m1 > -eps) {
lingkarankecil = m1;
}
}
printf("%.7lf", (phi * (lingkaranbesar * lingkaranbesar -
lingkarankecil * lingkarankecil)));
}
|
#include <bits/stdc++.h>
using namespace std;
using namespace std;
struct Point {
double x, y;
Point(double _x, double _y) {
x = _x;
y = _y;
}
Point() {}
double mod() { return sqrt(x * x + y * y); }
double mod2() { return x * x + y * y; }
double arg() { return atan2(y, x); }
Point ort() { return Point(-y, x); }
Point rev() { return Point(y, x); }
Point unit() {
double k = mod();
return Point(x / k, y / k);
}
void print() { printf("%lf %lf\n", x, y); }
void read() { scanf("%lf%lf", &x, &y); }
};
bool operator<(const Point &P1, const Point &P2) {
return (P1.x != P2.x) ? (P1.x < P2.x) : (P1.y < P2.y);
}
bool operator==(const Point &P1, const Point &P2) {
return fabs(P1.x - P2.x) < 1e-6 && fabs(P1.y - P2.y) < 1e-6;
}
bool operator>(const Point &P1, const Point &P2) {
return !(P1 == P2) && !(P1 < P2);
}
bool operator!=(const Point &P1, const Point &P2) { return !(P1 == P2); }
Point operator-(const Point &p1, const Point &p2) {
return Point(p1.x - p2.x, p1.y - p2.y);
}
Point operator+(const Point &p1, const Point &p2) {
return Point(p1.x + p2.x, p1.y + p2.y);
}
Point operator*(const Point &p, double k) { return Point(p.x * k, p.y * k); }
Point operator/(const Point &p, double k) { return Point(p.x / k, p.y / k); }
double dot(const Point &v1, const Point &v2) {
return v1.x * v2.x + v1.y * v2.y;
}
double cross(const Point &v1, const Point &v2) {
return v1.x * v2.y - v1.y * v2.x;
}
double dis(const Point &P1, const Point &P2) { return (P1 - P2).mod(); }
double area(const Point &A, const Point &B, const Point &C) {
return cross(B - A, C - A);
}
double areaHeron(double a, double b, double c) {
double s = (a + b + c) / 2;
return sqrt(s * (s - a) * (s - b) * (s - c));
}
double areaHeron(double a, double b, double c, double d) {
double s = (a + b + c + d) / 2;
return sqrt((s - a) * (s - b) * (s - c) * (s - d));
}
double circumradius(double a, double b, double c) {
return a * b * c / (4 * areaHeron(a, b, c));
}
Point rotate(Point A, Point C, double teta) {
Point T = Point(A.x - C.x, A.y - C.y);
return C + Point(T.x * cos(teta) - T.y * sin(teta),
T.y * cos(teta) + T.x * sin(teta));
}
struct line {
Point p1, p2;
line(Point _p1, Point _p2) {
p1 = _p1;
p2 = _p2;
}
line() {}
Point dir() { return p2 - p1; }
double mod() { return (p2 - p1).mod(); }
};
bool isAntihorario(Point *poli, int n) {
int top = 0;
for (int i = 0; i < n; i++)
if (poli[top].y < poli[i].y) top = i;
return poli[(top - 1 + n) % n].x > poli[(top + 1 + n) % n].x;
}
double disPointToLine(Point P, line L) {
Point v = P - L.p1;
return fabs(cross(v, L.dir())) / L.mod();
}
double disLineToPoint(Point P, line L) {
Point v = L.p2 - L.p1;
Point v1 = P - L.p1;
Point v2 = P - L.p2;
if (dot(v, v1) <= 0) return v1.mod();
if (dot(v, v2) >= 0) return v2.mod();
return fabs(cross(v1, v)) / v.mod();
}
bool between(const Point &A, const Point &B, const Point &P) {
return P.x + 1e-6 >= min(A.x, B.x) && P.x <= max(A.x, B.x) + 1e-6 &&
P.y + 1e-6 >= min(A.y, B.y) && P.y <= max(A.y, B.y) + 1e-6;
}
bool onSegment(Point P, line L) {
return fabs(cross(L.dir(), P - L.p1)) < 1e-6 &&
dot(P - L.p1, P - L.p2) < 1e-6;
}
bool intersects(line L1, line L2) {
if (onSegment(L1.p1, L2)) return true;
if (onSegment(L1.p2, L2)) return true;
if (onSegment(L2.p1, L1)) return true;
if (onSegment(L2.p2, L1)) return true;
double A11 = cross(L1.dir(), L2.p1 - L1.p1);
double A12 = cross(L1.dir(), L2.p2 - L1.p1);
double A21 = cross(L2.dir(), L1.p1 - L2.p1);
double A22 = cross(L2.dir(), L1.p2 - L2.p1);
if (A11 > 1e-6) swap(A11, A12);
if (A21 > 1e-6) swap(A21, A22);
return (A11 < 0 && A12 > 1e-6) && (A21 < 0 && A22 > 1e-6);
}
Point lineIntersection(line S1, line S2) {
return S1.p1 + S1.dir() * (cross(S2.p1 - S1.p1, S2.dir()) /
cross(S1.dir(), S2.dir()));
}
Point circumcenter(const Point &A, const Point &B, const Point &C) {
return (A + B + (A - B).ort() * dot(C - B, A - C) / cross(A - B, A - C)) / 2;
}
double distSeg(line s1, line s2) {
double ans = (1 << 30);
ans = min(ans, disLineToPoint(s1.p1, s2));
ans = min(ans, disLineToPoint(s1.p2, s2));
ans = min(ans, disLineToPoint(s2.p1, s1));
ans = min(ans, disLineToPoint(s2.p2, s1));
return ans;
}
double area(vector<Point> &P) {
double ans = 0;
int n = P.size();
for (int i = 0; i < n; i++) ans += cross(P[i], P[(i + 1) % n]);
return fabs(ans) / 2.0;
}
Point P[1000005], C;
pair<double, double> getInterval(int p1, int p2) {
double d1 = (P[p1] - C).mod2();
double d2 = (P[p2] - C).mod2();
double maxi = max(d1, d2);
Point dir = P[p1] - P[p2];
Point v1 = C - dir.ort() * sqrt(maxi), v2 = C + dir.ort() * sqrt(maxi);
line S1 = line(P[p1], P[p2]);
line S2 = line(v1, v2);
if (!intersects(S1, S2)) return make_pair(min(d1, d2), maxi);
Point I = lineIntersection(S1, S2);
double mini = (C - I).mod2();
return make_pair(mini, maxi);
}
int main() {
int n;
while (cin >> n) {
C.read();
for (int i = 0; i < n; i++) P[i].read();
vector<pair<double, double> > v;
for (int i = 0; i < n; i++) {
v.push_back(getInterval(i, (i + 1) % n));
}
sort(v.begin(), v.end());
double ans = 0, last = -1;
if (v.size() > 0) ans += v[0].second - v[0].first, last = v[0].second;
for (int i = 1; i < v.size(); i++) {
if (v[i].first > last) {
ans += v[i].second - v[i].first;
} else if (v[i].second > last)
ans += v[i].second - last;
last = max(last, v[i].second);
}
ans = ans * (atan2(0, -1));
printf("%.10lf\n", ans);
}
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
struct pt {
long long x, y;
pt() : x(0), y(0) {}
pt(long long x, long long y) : x(x), y(y) {}
};
bool cmp(pt a, pt b) { return a.x < b.x || a.x == b.x && a.y < b.y; }
bool cw(pt a, pt b, pt c) {
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < 0;
}
bool ccw(pt a, pt b, pt c) {
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0;
}
inline long long area(pt a, pt b, pt c) {
long long res = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
return (res > 0 ? 1 : (res < 0 ? -1 : 0));
}
inline bool intersect_1(long long a, long long b, long long c, long long d) {
if (a > b) swap(a, b);
if (c > d) swap(c, d);
return max(a, c) <= min(b, d);
}
bool intersect(pt a, pt b, pt c, pt d) {
return intersect_1(a.x, b.x, c.x, d.x) && intersect_1(a.y, b.y, c.y, d.y) &&
area(a, b, c) * area(a, b, d) <= 0 &&
area(c, d, a) * area(c, d, b) <= 0;
}
const double pi = 2.0 * acos(0.0);
double getDist(pt p, pt a, pt b) {
double A = a.y - b.y;
double B = b.x - a.x;
double C = a.x * b.y - a.y * b.x;
double d = hypot((double)(A), (double)(B));
double len = (A * p.x + B * p.y + C) / d;
double dx = A / d;
double dy = B / d;
double x = (double)(p.x) - len * dx;
double y = (double)(p.y) - len * dy;
double u = hypot((double)(a.x - b.x), (double)(a.y - b.y));
double v = hypot((double)(a.x) - x, (double)(a.y) - y);
double w = hypot((double)(b.x) - x, (double)(b.y) - y);
if (fabs(u - v - w) < 1e-9) {
return fabs(len);
}
return hypot((double)(p.x - a.x), (double)(p.y - a.y));
}
int main() {
int n;
scanf("%d", &n);
pt p;
scanf("%I64d%I64d", &p.x, &p.y);
vector<pt> a(n);
for (int i = 0; i < n; ++i) {
scanf("%I64d%I64d", &a[i].x, &a[i].y);
}
double l = 1e10, r = 0.0;
for (int i = 0; i < a.size(); ++i) {
double d = hypot((double)(p.x - a[i].x), (double)(p.y - a[i].y));
l = min(l, d);
r = max(r, d);
d = getDist(p, a[i], a[(i + 1) % a.size()]);
l = min(l, d);
r = max(r, d);
}
int cnt = 0;
for (int i = 0; i < a.size(); ++i) {
if (intersect(a[i], a[(i + 1) % a.size()], p,
pt(p.x + 1000000000, p.y + 1000000001))) {
++cnt;
}
}
if (cnt % 2 == 1) {
printf("%.10lf\n", pi * r * r);
} else {
printf("%.10lf\n", pi * (r * r - l * l));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
struct Point {
double x, y;
Point() { x = y = 0; }
Point(double a, double b) {
x = a;
y = b;
}
};
struct vec {
double x, y;
};
struct Line {
double a, b, c;
};
double dis(Point a, Point b) {
return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2));
}
bool issame(Point A, Point B) {
double a = A.x - B.x;
double b = A.y - B.y;
if (abs(a) < 1e-7 && abs(b) < 1e-7) return 1;
return 0;
}
vec Vector(Point a, Point b) {
vec p;
p.x = b.x - a.x;
p.y = b.y - a.y;
return p;
}
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; }
double length(vec a) { return sqrt(pow(a.x, 2) + pow(a.y, 2)); }
double dist(Point a, Point b, Point c) {
vec AB = Vector(a, b), AC = Vector(a, c), BC = Vector(b, c),
BA = Vector(b, a);
if (dot(AB, BC) > 0) return dis(c, b);
if (dot(BA, AC) > 0) return dis(a, c);
return abs(cross(AB, AC) / (length(AB)));
}
Point A[1000010];
int main() {
int n = read(), a = read(), b = read();
double mini = 10000000000000000;
double maxi = -1;
for (int i = 0; i < n; ++i) {
int c = read(), d = read();
A[i] = Point(c, d);
maxi = max(maxi, dis(A[i], Point(a, b)));
}
for (int i = 0; i < n; ++i) {
mini = min(mini, dist(A[i], A[(i + 1) % n], Point(a, b)));
}
double ans = acos(-1) * (maxi * maxi - mini * mini);
printf("%.17lf", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5 + 5;
const double eps = 1e-9;
int n;
pair<double, double> orig;
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);
}
struct Line {
pair<double, double> pi, pf;
double a, b, c;
void init(pair<double, double> p1, pair<double, double> p2) {
pi = p1, pf = p2;
a = p2.second - p1.second;
b = p1.first - p2.first;
c = a * p1.first + b * p1.second;
}
bool inside(pair<double, double> p) {
return sqrt(dist(p, pi)) + sqrt(dist(p, pf)) <= sqrt(dist(pi, pf)) + eps;
}
double shortestDist() {
if (b == 0) {
if (inside({c / a, orig.second})) {
return (c / a - orig.first) * (c / a - orig.first);
} else {
return min(dist(orig, pi), dist(orig, pf));
}
} else {
pair<double, double> pt;
double top = a * c / b + b * orig.first - a * orig.second,
bot = b + a * a / b;
pt.first = top / bot, pt.second = (c - a * pt.first) / b;
return inside(pt) ? dist(orig, pt) : min(dist(orig, pi), dist(orig, pf));
}
}
double longestDist() { return max(dist(orig, pi), dist(orig, pf)); }
void print() { printf("%lf %lf %lf\n", a, b, c); }
};
Line L[nax];
pair<double, double> P[nax];
int main() {
scanf("%d", &n);
scanf("%lf %lf", &orig.first, &orig.second);
for (int i = 0; i < n; ++i) scanf("%lf %lf", &P[i].first, &P[i].second);
for (int i = 0; i < n; ++i) L[i].init(P[i], P[(i + 1) % n]);
double r1 = 1e13, r2 = 0;
for (int i = 0; i < n; ++i) {
r1 = min(r1, L[i].shortestDist());
r2 = max(r2, L[i].longestDist());
}
cout << fixed << setprecision(12) << 3.14159265358979323846 * (r2 - r1)
<< endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<double, double> > v;
double dist(double x0, double y0, double x, double y) {
return ((x0 - x) * (x0 - x)) + ((y0 - y) * (y0 - y));
}
int main() {
int n, i, j;
double x0, y0, x, y, mn, mx, t1, t2, t3;
scanf("%d", &n);
scanf("%lf %lf", &x0, &y0);
for (i = 0; i < n; i++) {
scanf("%lf %lf", &x, &y);
v.push_back(make_pair(x, y));
}
mn = (double)LONG_LONG_MAX, mx = 0.0;
for (i = 0; i < n; i++) {
t1 = dist(x0, y0, v[i].first, v[i].second);
mn = min(mn, t1);
mx = max(mx, t1);
}
for (i = 0; i < n; i++) {
j = (i + 1) % n;
t1 = dist(v[i].first, v[i].second, v[j].first, v[j].second);
t2 = dist(v[i].first, v[i].second, x0, y0);
t3 = dist(v[j].first, v[j].second, x0, y0);
if (t2 < t1 + t3 && t3 < t1 + t2) {
t2 = ((v[i].second - v[j].second) * x0) -
((v[i].first - v[j].first) * y0) + (v[i].first * v[j].second) -
(v[i].second * v[j].first);
t2 = (t2 * t2);
t3 = t2 / t1;
mn = min(mn, t3);
mx = max(mx, t3);
}
}
t1 = (double)3.14159265359 * (mx - mn);
printf("%0.6lf\n", t1);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const double pi = acos(-1);
struct point {
double x, y;
};
int n;
double minR, maxR;
point p, v[N];
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 dist_to_seg(point A, point B, point C) {
if (B.x == C.x) {
if (A.y >= min(B.y, C.y) && A.y <= max(B.y, C.y))
return (((A.x - B.x) > 0) ? (A.x - B.x) : (-(A.x - B.x)));
return min(dist(A, B), dist(A, C));
}
if (B.y == C.y) {
if (A.x >= min(B.x, C.x) && A.x <= max(B.x, C.x))
return (((A.y - B.y) > 0) ? (A.y - B.y) : (-(A.y - B.y)));
return min(dist(A, B), dist(A, C));
}
double k = (B.y - C.y) / (B.x - C.x);
double crx = (k * B.x - B.y + A.x / k + A.y) / (k + 1 / k);
if (crx >= min(B.x, C.x) && crx <= max(B.x, C.x)) {
double cry = k * (crx - B.x) + B.y;
return (((k * A.x - A.y + B.y - k * B.x) > 0)
? (k * A.x - A.y + B.y - k * B.x)
: (-(k * A.x - A.y + B.y - k * B.x))) /
sqrt(k * k + 1);
}
return min(dist(A, B), dist(A, C));
}
int main() {
scanf("%d%lf%lf", &n, &p.x, &p.y);
for (int i = 1; i <= (n); i++) {
scanf("%lf%lf", &v[i].x, &v[i].y);
maxR = max(maxR, ((dist(p, v[i])) * (dist(p, v[i]))));
}
minR = ((dist_to_seg(p, v[1], v[n])) * (dist_to_seg(p, v[1], v[n])));
for (int i = 1; i <= (n - 1); i++)
minR = min(minR, ((dist_to_seg(p, v[i], v[i + 1])) *
(dist_to_seg(p, v[i], v[i + 1]))));
printf("%.11lf\n", pi * (maxR - minR));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
struct point {
point() {}
point(double x, double y) : x(x), y(y) {}
double x, y;
};
struct segment {
segment() {}
segment(point a, point b) : a(a), b(b) {}
point a, b;
};
template <class T>
T sqr(T a) {
return a * a;
}
double dist(point a, point b) { return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y)); }
double crossProduct(point a1, point a2, point b1, point b2) {
return ((a2.x - a1.x) * (b2.y - b1.y) - (a2.y - a1.y) * (b2.x - b1.x));
}
double dotProduct(point a1, point a2, point b1, point b2) {
return ((a2.x - a1.x) * (b2.x - b1.x) + (a2.y - a1.y) * (b2.y - b1.y));
}
double dist(point c, segment seg) {
if (dotProduct(seg.a, seg.b, seg.a, c) <= 0 ||
dotProduct(seg.b, seg.a, seg.b, c) <= 0)
return min(dist(c, seg.a), dist(c, seg.b));
return abs(crossProduct(seg.a, seg.b, seg.a, c) / dist(seg.a, seg.b));
}
int main() {
int n;
point a;
cin >> n;
cin >> a.x >> a.y;
double dmax = 0, dmin = 1e18;
vector<point> b(n);
for (int i = 0; i < n; i++) cin >> b[i].x >> b[i].y;
for (int i = 0; i < n; i++) {
dmax = max(dmax, dist(a, b[i]));
dmin = min(dmin, dist(a, b[i]));
dmin = min(dmin, dist(a, segment(b[i], b[(i + 1) % n])));
}
double ans = PI * (dmax * dmax - dmin * dmin);
printf("%.12lf", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
double sx, sy, Min = 1.0e9, Max = 0, M1 = 1.0e9, M2 = 1.0e9, U1 = -1.0e9,
U2 = -1.0e9;
double x[100002], y[100002];
int main() {
int n;
scanf("%d", &n);
cin >> sx >> sy;
bool flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0;
for (int i = 1; i <= n; i++) {
scanf("%lf %lf", &x[i], &y[i]);
}
int sum = 0;
for (int i = 1; i <= n; i++) {
double d1 = x[i] - sx;
double d2 = y[i] - sy;
double d = sqrt(d1 * d1 + d2 * d2);
Min = min(Min, d);
Max = max(Max, d);
int to;
if (i == 1)
to = n;
else
to = i - 1;
if (x[i] - x[to] == 0) {
if (sy >= min(y[i], y[to]) && sy <= max(y[i], y[to])) {
Min = min(Min, abs(x[i] - sx));
}
continue;
}
double k = (y[i] - y[to]) / (x[i] - x[to]);
double b = y[i] - k * x[i];
double k2 = -1.0 / k;
double b2 = sy - sx * k2;
double x2 = (b - b2) / (k2 - k);
double y2 = x2 * k2 + b2;
if (k == 0) x2 = sx, y2 = b;
if (min(x[i], x[to]) <= x2 && x2 <= max(x[i], x[to])) {
d1 = y2 - sy;
d2 = x2 - sx;
d = sqrt(d1 * d1 + d2 * d2);
Min = min(Min, d);
}
}
printf("%0.7lf", pi * Max * Max - pi * Min * Min);
}
|
#include <bits/stdc++.h>
using namespace std;
double x[100005], y[100005];
int main() {
int n;
double x1, y1;
cin >> n >> x1 >> y1;
double ma = 0, mi = 1000000000000000000000.0;
for (int i = 1; i <= n; i++) cin >> x[i] >> y[i];
x[0] = x[n];
y[0] = y[n];
for (int i = 1; i <= n; i++) {
double dist = (x[i] - x1) * (x[i] - x1) + (y[i] - y1) * (y[i] - y1);
mi = min(mi, dist);
ma = max(ma, dist);
if (x[i] == x[i - 1]) {
if (y1 >= y[i] && y1 <= y[i - 1]) {
dist = abs(x1 - x[i - 1]);
dist = dist * dist;
} else {
if (y1 >= y[i - 1] && y1 <= y[i]) {
dist = abs(x1 - x[i - 1]);
dist = dist * dist;
} else
continue;
}
} else {
double m = (y[i - 1] - y[i]) / (double)(x[i - 1] - x[i]);
double c = y[i - 1] - m * x[i - 1];
if (y[i] == y[i - 1]) {
if (x1 >= x[i - 1] && x1 <= x[i]) {
dist = abs(y[i] - y1);
dist = dist * dist;
} else {
if (x1 >= x[i] && x1 <= x[i - 1]) {
dist = abs(y[i] - y1);
dist = dist * dist;
} else
continue;
}
} else {
double m1 = -1 / (double)m;
double c1 = y1 - m1 * x1;
if (m == m1) continue;
double x2 = (c1 - c) / (double)(m - m1);
double y2 = m1 * x2 + c1;
if (x2 >= x[i] && x2 <= x[i - 1]) {
dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
} else {
if (x2 >= x[i - 1] && x2 <= x[i]) {
dist = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
} else
continue;
}
}
}
mi = min(mi, dist);
}
ma = 3.14159265358979323846264338327950288419 * (ma - mi);
printf("%.9lf\n", (ma));
}
|
#include <bits/stdc++.h>
using namespace std;
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);
}
};
struct C {
complex<double> p;
double r;
C(const complex<double>& p, double r) : p(p), r(r) {}
};
complex<double> proj(complex<double> a1, complex<double> a2,
complex<double> p) {
return a1 + dot(a2 - a1, p - a1) / norm(a2 - a1) * (a2 - a1);
}
double distLP(complex<double> a1, complex<double> a2, complex<double> p) {
return abs(proj(a1, a2, p) - p);
}
const double EPS = 1e-9;
int ccw(complex<double> a, complex<double> b, complex<double> c) {
b -= a;
c -= a;
if (cross(b, c) > EPS) return +1;
if (cross(b, c) < -EPS) return -1;
if (dot(b, c) < -EPS) return +2;
if (norm(b) < norm(c)) return -2;
return 0;
}
bool isecSP(complex<double> a1, complex<double> a2, complex<double> b) {
return !ccw(a1, a2, b);
}
double distSP(complex<double> a1, complex<double> a2, complex<double> p) {
complex<double> r = proj(a1, a2, p);
if (isecSP(a1, a2, r)) return abs(r - p);
return min(abs(a1 - p), abs(a2 - p));
}
template <class T = int, T divided_by = 10>
constexpr T PINF() {
return std::numeric_limits<T>::max() / divided_by;
}
template <class T = int, T divided_by = 10>
constexpr T MINF() {
return std::numeric_limits<T>::lowest() / divided_by;
}
double My_PI = 2 * acos(0.0);
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
long long n, x, y;
cin >> n >> x >> y;
double dbx = x, dby = y;
complex<double> pos = {dbx, dby};
vector<complex<double> > plist;
double mind = numeric_limits<double>::max();
double maxd = numeric_limits<double>::lowest();
double px, py;
for (int i = 0; i < n; ++i) {
cin >> px >> py;
plist.push_back({px, py});
complex<double> dxy = pos - plist[i];
double dist = sqrt(norm(dxy));
maxd = max(maxd, dist);
mind = min(mind, dist);
}
if (true) {
for (int i = 0; i < n; ++i) {
int ni = (i + 1) % n;
mind = min(mind, distSP(plist[i], plist[ni], pos));
}
}
double ret = maxd * maxd * My_PI - mind * mind * My_PI;
cout << ret << endl;
return 0;
}
|
#include <bits/stdc++.h>
double Px, Py, Hx, Hy, Dx, Dy;
double D() {
double X = (Px > Dx ? Px - Dx : Dx - Px), Y = (Py > Dy ? Py - Dy : Dy - Py);
return X * X + Y * Y;
}
double H() {
double X, Y, PX = Dy - Hy, PY = Hx - Dx, HX = Dx - Hx, HY = Dy - Hy, i, j, L,
A, B, mHX, mHY, r = 1e18;
A = Hx - Px;
B = Hy - Py;
mHX = -HX;
mHY = -HY;
L = (PX * mHY - mHX * PY);
i = (A * mHY - mHX * B);
j = (PX * B - A * PY);
i /= L;
j /= L;
X = Px + i * PX;
Y = Py + i * PY;
if (((Hx > Dx ? Hx - Dx : Dx - Hx) > 1e-6 &&
((X > Hx + 1e-6 && X < Dx - 1e-6) ||
(X < Hx - 1e-6 && X > Dx + 1e-6))) ||
((Hy > Dy ? Hy - Dy : Dy - Hy) > 1e-6 &&
((Y > Hy + 1e-6 && Y < Dy - 1e-6) ||
(Y < Hy - 1e-6 && Y > Dy + 1e-6)))) {
HX = Dx;
HY = Dy;
Dx = X;
Dy = Y;
r = D();
Dx = HX;
Dy = HY;
}
return r;
}
int main() {
unsigned q;
double lo, hi, mi, Fx, Fy;
scanf("%u%lf%lf%lf%lf", &q, &Px, &Py, &Dx, &Dy);
Fx = Dx;
Fy = Dy;
for (lo = hi = D(); --q;) {
Hx = Dx;
Hy = Dy;
scanf("%lf%lf", &Dx, &Dy);
mi = D();
if (mi < lo) lo = mi;
if (mi > hi) hi = mi;
mi = H();
if (mi < lo) lo = mi;
}
Hx = Fx;
Hy = Fy;
mi = H();
if (mi < lo) lo = mi;
printf("%.18lf\n", (hi - lo) * 3.1415926535897932384626433832795);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, xs[233333], ys[233333], px, py;
int main() {
scanf("%d%d%d", &n, &px, &py);
for (int i = 0; i < n; i++) {
scanf("%d%d", xs + i, ys + i);
}
double maxd = 0, mind = 20000000000000LL;
for (int i = 0; i < n; i++) {
maxd = max(maxd, sqrt(double(xs[i] - px) * (xs[i] - px) +
double(ys[i] - py) * (ys[i] - py)));
}
for (int i = 0; i < n; i++) {
double x1 = xs[i], y1 = ys[i], x2 = xs[(i + 1) % n], y2 = ys[(i + 1) % n];
double A = y1 - y2, B = x2 - x1, C = x1 * y2 - x2 * y1;
double x0 = px, y0 = py;
double qx = (B * B * x0 - A * B * y0 - A * C) / (A * A + B * B),
qy = (A * A * y0 - A * B * x0 - B * C) / (A * A + B * B);
double cd = 20000000000000LL;
cd = min(cd,
sqrt(double(x1 - px) * (x1 - px) + double(y1 - py) * (y1 - py)));
cd = min(cd,
sqrt(double(x2 - px) * (x2 - px) + double(y2 - py) * (y2 - py)));
if (qx < min(x1, x2) || qx > max(x1, x2))
;
else {
cd = min(cd, fabs(A * x0 + B * y0 + C) / sqrt(A * A + B * B));
}
mind = min(mind, cd);
}
printf("%.23lf\n", asin(1) * 2 * (maxd * maxd - mind * mind));
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = int(1e5) + 3;
int cmpfunc(const void *a, const void *b) { return *(int *)a - *(int *)b; }
vector<pair<long long int, long long int> > a[N];
double ax[N];
double ay[N];
double FindDistanceToSegment(double x1, double y1, double x2, double y2,
double pointX, double pointY) {
double diffX = x2 - x1;
double diffY = y2 - y1;
if ((diffX == 0) && (diffY == 0)) {
diffX = pointX - x1;
diffY = pointY - y1;
return sqrt(diffX * diffX + diffY * diffY);
}
double 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 diffX * diffX + diffY * diffY;
}
int main() {
double n, x, y;
cin >> n >> x >> y;
for (int i = 0; i < n; i++) {
long long int t1, t2;
cin >> t1 >> t2;
ax[i] = (double)t1;
ay[i] = (double)t2;
}
double maxi = 0;
double mini = DBL_MAX;
for (int i = 0; i < n; i++) {
maxi = max(maxi, (x - ax[i]) * (x - ax[i]) + (y - ay[i]) * (y - ay[i]));
mini = min(mini, (x - ax[i]) * (x - ax[i]) + (y - ay[i]) * (y - ay[i]));
}
for (int i = 0; i < n - 1; i++) {
mini = min(mini,
FindDistanceToSegment(ax[i], ay[i], ax[i + 1], ay[i + 1], x, y));
}
mini = min(mini, FindDistanceToSegment(ax[0], ay[0], ax[int(n) - 1],
ay[int(n) - 1], x, y));
printf("%.8lf\n", double(3.141592653) * (maxi - mini));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long x[100010], y[100010];
double d[100010], dd[100010];
int main() {
long long n, x0, y0;
while (cin >> n >> x0 >> y0) {
double minr = 10000000;
double maxr = 0.0;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
long long rr = (x[i] - x0) * (x[i] - x0) + (y[i] - y0) * (y[i] - y0);
d[i] = sqrt((double)rr);
minr = min(minr, d[i]);
maxr = max(maxr, d[i]);
}
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
long long rr =
(x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
dd[i] = sqrt((double)rr);
if (d[i] * d[i] + rr < d[j] * d[j] || d[j] * d[j] + rr < d[i] * d[i])
continue;
double a = acos((d[i] * d[i] + d[j] * d[j] - rr) / d[i] / d[j] / 2);
double h = d[i] * d[j] * sin(a) / dd[i];
minr = min(minr, h);
}
double PI = 2.0 * acos((double)0.0);
double ans = PI * (maxr * maxr - minr * minr);
printf("%.10lf\n", ans);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long double dy(long double x1, long double y1, long double x2, long double y2) {
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
long double di(long double x, long double y, long double x1, long double y1,
long double x2, long double y2) {
long double A = y1 - y2;
long double B = x2 - x1;
long double C = -x1 * A - y1 * B;
long double a = dy(x, y, x1, y1);
a = a * a;
long double b = dy(x, y, x2, y2);
b = b * b;
long double c = dy(x1, y1, x2, y2);
c = c * c;
if (a > b + c) return sqrt(b + 0.0);
if (b > a + c) return sqrt(a + 0.0);
long double dis = abs(A * x + B * y + C) / sqrt(0.0 + A * A + B * B);
return dis;
}
pair<int, int> a[N];
const long double EPS = 1e-6;
int main() {
int n, x, y;
long double minR = 1e18;
long double maxR = -1e18;
scanf("%d %d %d", &n, &x, &y);
int lastx, lasty;
for (int i = 0; i < n; i++) {
int xx, yy;
scanf("%d %d", &xx, &yy);
a[i] = make_pair(xx, yy);
minR = min(minR, dy(x, y, xx, yy));
maxR = max(maxR, dy(x, y, xx, yy));
}
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
long double dim =
di(x, y, a[i].first, a[i].second, a[j].first, a[j].second);
minR = min(minR, dim);
maxR = max(maxR, dim);
}
long double PI = 3.1415926535897932384626433832795;
long double ans = PI * (maxR * maxR - minR * minR);
cout.precision(6);
cout << fixed << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
struct pt {
double x, y;
pt() {}
pt(int a, int b) : x(a), y(b) {}
};
vector<pt> a;
bool cmp(pt a, pt b) { return a.x < b.x || a.x == b.x && a.y < b.y; }
bool cw(pt a, pt b, pt c) {
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) < 0;
}
bool ccw(pt a, pt b, pt c) {
return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y) > 0;
}
void convex_hull(vector<pt>& a) {
if (a.size() == 1) return;
sort(a.begin(), a.end(), &cmp);
pt p1 = a[0], p2 = a.back();
vector<pt> up, down;
up.push_back(p1);
down.push_back(p1);
for (int i = 1; i < a.size(); ++i) {
if (i == a.size() - 1 || cw(p1, a[i], p2)) {
while (up.size() >= 2 && !cw(up[up.size() - 2], up[up.size() - 1], a[i]))
up.pop_back();
up.push_back(a[i]);
}
if (i == a.size() - 1 || ccw(p1, a[i], p2)) {
while (down.size() >= 2 &&
!ccw(down[down.size() - 2], down[down.size() - 1], a[i]))
down.pop_back();
down.push_back(a[i]);
}
}
a.clear();
for (int i = 0; i < up.size(); ++i) a.push_back(up[i]);
for (int i = down.size() - 2; i > 0; --i) a.push_back(down[i]);
}
double range(double xa, double ya, double xb, double yb) {
xa -= xb, ya -= yb;
return sqrt(xa * xa + ya * ya + .0);
}
inline double dist(double xa, double ya, double xb, double yb, double x,
double y) {
double vx = xb - xa;
double vy = yb - ya;
double d = sqrt(vx * vx + vy * vy);
vx /= d;
vy /= d;
double l = 0, r = range(xa, ya, xb, yb), m1, m2, c1, c2;
for (int i = 0; i <= 100; ++i) {
m1 = l + (r - l) / 3;
m2 = r - (r - l) / 3;
c1 = range(xa + m1 * vx, ya + m1 * vy, x, y);
c2 = range(xa + m2 * vx, ya + m2 * vy, x, y);
if (c1 > c2)
l = m1;
else
r = m2;
}
return range(xa + r * vx, ya + r * vy, x, y);
}
int n, cx, cy;
double d, dd, mn = INT_MAX, mx = INT_MIN;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> cx >> cy;
for (int i = 1; i <= n; ++i) {
int x, y;
cin >> x >> y;
a.push_back(pt(x, y));
}
for (int i = 0; i < a.size(); ++i) {
d = range(a[i].x, a[i].y, cx, cy);
if (d < mn) mn = d;
if (d > mx) mx = d;
if (i > 0) {
dd = dist(a[i - 1].x, a[i - 1].y, a[i].x, a[i].y, cx, cy);
if (dd < mn) mn = dd;
if (dd > mx) mx = dd;
}
if (i == a.size() - 1) {
dd = dist(a[0].x, a[0].y, a[i].x, a[i].y, cx, cy);
if (dd < mn) mn = dd;
if (dd > mx) mx = dd;
}
}
double ans = pi * (mx * mx - mn * mn);
printf("%.7f\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
struct point_t {
double x, y;
};
double cross(point_t const &O, point_t const &A, point_t const &B) {
double xOA = A.x - O.x;
double yOA = A.y - O.y;
double xOB = B.x - O.x;
double yOB = B.y - O.y;
return xOA * yOB - xOB * yOA;
}
double PointTOline(point_t const &a, point_t const &b, point_t const &p) {
double ap_ab = (b.x - a.x) * (p.x - a.x) + (b.y - a.y) * (p.y - a.y);
if (ap_ab <= 0)
return sqrt((p.x - a.x) * (p.x - a.x) + (p.y - a.y) * (p.y - a.y));
double d2 = (b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y);
if (ap_ab >= d2)
return sqrt((p.x - b.x) * (p.x - b.x) + (p.y - b.y) * (p.y - b.y));
double r = ap_ab / d2;
double px = a.x + (b.x - a.x) * r;
double py = a.y + (b.y - a.y) * r;
return sqrt((p.x - px) * (p.x - px) + (p.y - py) * (p.y - py));
}
bool isOnline(point_t const &a, point_t const &b, point_t const &po) {
return po.x >= min(a.x, b.x) && po.x <= max(a.x, b.x) &&
po.y >= min(a.y, b.y) && po.y <= max(a.y, b.y) &&
(po.x - a.x) * (b.y - a.y) == (po.y - a.y) * (b.x - a.x);
}
point_t p[MAXN];
int main() {
int n;
double x, y, a, b;
while (~scanf("%d%lf%lf", &n, &x, &y)) {
point_t po;
po.x = x, po.y = y;
double maxx = 0;
for (int i = 0; i <= n - 1; i++) {
scanf("%lf%lf", &a, &b);
double temp = sqrt((a - x) * (a - x) + (b - y) * (b - y));
p[i].x = a, p[i].y = b;
if (temp > maxx) maxx = temp;
}
double minn = PointTOline(p[0], p[1], po);
p[n] = p[0];
for (int i = 1; i < n; ++i)
minn = min(minn, PointTOline(p[i], p[i + 1], po));
printf("%lf\n", acos(-1) * (maxx * maxx - minn * minn));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.00);
const long long inf = 1000000000000000000;
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; }
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.00) return a;
if (r > 1.00) return b;
return a + (b - a) * r;
}
double DistancePointSegment(PT a, PT b, PT c) {
return sqrt(dist2(c, ProjectPointSegment(a, b, c)));
}
vector<PT> v;
int main() {
int n;
cin >> n;
PT base;
cin >> base.x >> base.y;
double near = 1e20;
double far = 0.00;
for (int i = 1; i <= n; i++) {
PT p;
cin >> p.x >> p.y;
v.push_back(p);
far = max(far, sqrt(dist2(p, base)));
}
for (int i = 0; i < (n - 1); i++) {
double dd = DistancePointSegment(v.at(i), v.at(i + 1), base);
near = min(near, dd);
far = max(far, dd);
}
double dd = DistancePointSegment(v.at(0), v.at(n - 1), base);
near = min(near, dd);
far = max(far, dd);
double r = near;
double R = far;
double ans = pi * ((R * R) - (r * r));
cout.precision(20);
cout << fixed << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
double distance(long long x0, long long y0, double x1, double y1) {
return std::sqrt((x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1));
}
double line_segment_point_closest_distance(long long px, long long py,
long long x1, long long y1,
long long x2, long long y2) {
long long minx = std::min(x1, x2);
long long maxx = std::max(x1, x2);
long long miny = std::min(y1, y2);
long long maxy = std::max(y1, y2);
double xint, yint;
if (x1 - x2 == 0) {
xint = x2;
yint = py;
} else if (y1 - y2 == 0) {
xint = px;
yint = y2;
} else {
double m1 = (y1 - y2) / static_cast<double>(x1 - x2);
double m2 = -1 / m1;
xint = (-m2 * px + m1 * x1 + py - y1) / (m1 - m2);
yint = m1 * (xint - x1) + y1;
}
if (xint <= maxx and xint >= minx and yint <= maxy and yint >= miny) {
return distance(px, py, xint, yint);
} else if (distance(x1, y1, xint, yint) >= distance(x2, y2, xint, yint)) {
return distance(px, py, x2, y2);
} else {
return distance(px, py, x1, y1);
}
}
int main() {
long long n, px, py;
std::cin >> n >> px >> py;
long long fx, fy, lx, ly;
std::cin >> fx >> fy;
lx = fx;
ly = fy;
double min = distance(px, py, fx, fy);
double max = min;
for (long i = 1; i < n; i++) {
long long ix, iy;
std::cin >> ix >> iy;
double dist = distance(px, py, ix, iy);
max = std::max(max, dist);
dist = line_segment_point_closest_distance(px, py, lx, ly, ix, iy);
min = std::min(min, dist);
lx = ix;
ly = iy;
}
double dist = line_segment_point_closest_distance(px, py, lx, ly, fx, fy);
min = std::min(min, dist);
double pi = 3.141592653589793238462643383279502884;
std::cout.precision(10);
std::cout << pi * (max * max - min * min) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007, BIG = 0x3f3f3f3f;
const double PI = 3.14159265358979323846, EPS = 0.0000000001;
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point Rotate(double theta) {
double rad = theta * PI / 180.;
return {x * cos(rad) - y * sin(rad), x * sin(rad) + y * cos(rad)};
}
Point Rotate_Around(double theta, const Point& axis) {
double rad = theta * PI / 180.;
return {(x - axis.x) * cos(rad) - (y - axis.y) * sin(rad) + axis.x,
(x - axis.x) * sin(rad) + (y - axis.y) * cos(rad) + axis.y};
}
};
bool operator==(const Point& p1, const Point& p2) {
return (fabs(p1.x - p2.x) < EPS) && (fabs(p1.y - p2.y) < EPS);
}
istream& operator>>(istream& is, Point& _a) {
is >> _a.x >> _a.y;
return is;
}
ostream& operator<<(ostream& os, Point& _a) {
os << _a.x << " " << _a.y;
return os;
}
double Euclidean_Distance(const Point& _a, const Point& _b) {
return hypot(_a.x - _b.x, _a.y - _b.y);
}
struct Line {
double a, b, c;
Line() {}
Line(double a, double b, double c) : a(a), b(b), c(c) {}
Line(const Point& _a, const Point& _b) {
if (fabs(_a.x - _b.x) < EPS) {
a = 1;
b = 0;
c = -_a.x;
} else {
a = -(_a.y - _b.y) / (_a.x - _b.x);
b = 1.;
c = -(a * _a.x) - _a.y;
}
}
};
Line Perpendicular_Line(const Line& _a, const Point& _p) {
double sl = 1. / (_a.a / _a.b);
double cc = _p.y - sl * _p.x;
return Line(-sl, 1, -cc);
}
bool Parallel_Lines(const Line& _a, const Line& _b) {
return (fabs(_a.a - _b.a) < EPS) && (fabs(_a.b - _b.b) < EPS);
}
bool operator==(const Line& _a, const Line& _b) {
return Parallel_Lines(_a, _b) && (fabs(_a.c - _b.c) < EPS);
}
Point Intersection(const Line& _a, const Line& _b) {
double w = _a.a * _b.b - _b.a * _a.b;
if (fabs(w) < EPS) {
cout << "Division by zero\n";
exit(0);
}
return {(_a.b * _b.c - _b.b * _a.c) / w, (_b.a * _a.c - _a.a * _b.c) / w};
}
struct Vec {
double x, y;
Vec() {}
Vec(double x, double y) : x(x), y(y) {}
Vec(const Point& _a, const Point& _b) : x(_b.x - _a.x), y(_b.y - _a.y) {}
Vec Scale(double _s) const { return {x * _s, y * _s}; }
double Squared_Norm() { return x * x + y * y; }
};
double operator*(const Vec& _a, const Vec& _b) {
return _a.x * _b.x + _a.y * _b.y;
}
double Cross_Product(const Vec& _a, const Vec& _b) {
return _a.x * _b.y - _a.y * _b.x;
}
double Cross_Product(const Point& _a, const Point& _b) {
return _a.x * _b.y - _a.y * _b.x;
}
Point Translate(const Point& _p, const Vec& _v) {
return {_p.x + _v.x, _p.y + _v.y};
}
Point Closest_Point_In_Line(const Point& _p, const Point& _a, const Point& _b) {
Vec ap(_a, _p), ab(_a, _b);
double u = ap * ab / ab.Squared_Norm();
return Translate(_a, ab.Scale(u));
}
double Distance_To_Line(const Point& _p, const Point& _a, const Point& _b) {
return Euclidean_Distance(_p, Closest_Point_In_Line(_p, _a, _b));
}
Point Closest_Point_In_Line_Segment(const Point& _p, const Point& _a,
const Point& _b) {
Vec ap(_a, _p), ab(_a, _b);
double u = ap * ab / ab.Squared_Norm();
if (u < 0.0) return {_a.x, _a.y};
if (u > 1.0) return {_b.x, _b.y};
return Translate(_a, ab.Scale(u));
}
double Distance_To_Line_Segment(const Point& _p, const Point& _a,
const Point& _b) {
return Euclidean_Distance(_p, Closest_Point_In_Line_Segment(_p, _a, _b));
}
double Angle(const Point& _a, const Point& _o, const Point& _b) {
Vec oa(_o, _a), ob(_o, _b);
return acos(oa * ob / sqrt(oa.Squared_Norm() * ob.Squared_Norm()));
}
double Angle_CCW_From_X_Axis(const Point& _a) {
if (fabs(_a.x) < EPS) {
if (fabs(_a.y) < EPS) return 0;
if (_a.y > 0) return PI / 2.;
return 3. * PI / 2.;
} else if (fabs(_a.y) < EPS) {
if (_a.x > 0) return 0;
return PI;
}
double ans = atan(_a.y / _a.x);
if (_a.y < 0) ans += PI;
return ans;
}
bool Left_Of_Line(const Point& _p, const Point& _a, const Point& _b) {
return Cross_Product(Vec(_a, _b), Vec(_a, _p)) > 0;
}
bool Collinear(const Point& _p, const Point& _a, const Point& _b) {
return fabs(Cross_Product(Vec(_a, _b), Vec(_a, _p))) < EPS;
}
struct Circle {
double radius, area, circumference;
Point possible_center1, possible_center2;
Circle(double radius) : radius(radius) {}
void Init() {
area = PI * radius * radius;
circumference = 2. * PI * radius;
}
bool Get_Center(const Point& p1, const Point& p2) {
double dSq = (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
double det = radius * radius / dSq - 0.25;
if (det < 0.) return 0;
double h = sqrt(det);
possible_center1.x = (p1.x + p2.x) * .5 + (p1.y - p2.y) * h;
possible_center1.y = (p1.y + p2.y) * .5 + (p2.x - p1.x) * h;
possible_center2.x = (p1.x + p2.x) * .5 + (p2.y - p1.y) * h;
possible_center2.y = (p1.y + p2.y) * .5 + (p1.x - p2.x) * h;
return 1;
}
};
struct Triangle {
Point p1, p2, p3;
double area, s1, s2, s3, semip;
void Init() {
semip = (s1 + s2 + s3) / 2;
area = sqrt(semip * (semip - s1) * (semip - s2) * (semip - s3));
}
Triangle(double s1, double s2, double s3) : s1(s1), s2(s2), s3(s3) { Init(); }
Triangle(const Point& p1, const Point& p2, const Point& p3)
: p1(p1), p2(p2), p3(p3) {
s1 = Euclidean_Distance(p1, p2);
s2 = Euclidean_Distance(p2, p3);
s3 = Euclidean_Distance(p1, p3);
Init();
}
double Incircle_Radius() { return area / semip; }
double Circumcircle_Radius() { return s1 * s2 * s3 / (4. * area); }
Point Circumcircle_Center() {
Point ans;
Point mid1 = Point((p1.x + p2.x) / 2, (p1.y + p2.y) / 2);
Point mid2 = Point((p2.x + p3.x) / 2, (p2.y + p3.y) / 2);
Line per1 = Perpendicular_Line(Line(p1, p2), mid1);
Line per2 = Perpendicular_Line(Line(p2, p3), mid2);
return Intersection(per1, per2);
}
Point Incircle_Center() {
double ratio = s1 / s3;
Point p = Translate(p2, Vec(p2, p3).Scale(ratio / (1 + ratio)));
ratio = s1 / s2;
p = Translate(p1, Vec(p1, p3).Scale(ratio / (1 + ratio)));
return Intersection(Line(p1, p), Line(p2, p));
}
};
struct Polygon {
vector<Point> vp;
Polygon() {}
void Add(const Point& _p) { vp.push_back(_p); }
double Perimeter() {
double ans = 0.0;
for (int i = 0; i < (int)vp.size() - 1; i++)
ans += Euclidean_Distance(vp[i], vp[i + 1]);
return ans;
}
double Area() {
double ans = 0.0, x1, y1, x2, y2;
for (int i = 0; i < (int)vp.size() - 1; i++) {
x1 = vp[i].x;
x2 = vp[i + 1].x;
y1 = vp[i].y;
y2 = vp[i + 1].y;
ans += (x1 * y2 - x2 * y1);
}
return fabs(ans) / 2.0;
}
bool Convex() {
int sz = (int)vp.size();
if (sz <= 3) return 0;
bool isLeft = Left_Of_Line(vp[2], vp[0], vp[1]);
for (int i = 1; i < sz - 1; i++)
if (Left_Of_Line(vp[(i + 2) == sz ? 1 : i + 2], vp[i], vp[i + 1]) !=
isLeft)
return 0;
return 1;
}
bool Contains_Point(const Point& _p) {
if ((int)vp.size() == 0) return 0;
double sum = 0;
for (int i = 0; i < (int)vp.size() - 1; i++) {
if (Left_Of_Line(vp[i + 1], _p, vp[i]))
sum += Angle(vp[i], _p, vp[i + 1]);
else
sum -= Angle(vp[i], _p, vp[i + 1]);
}
return fabs(fabs(sum) - 2. * PI) < EPS;
}
Point Line_Intersect_Seg(const Point& _p, const Point& _q, const Point& _A,
const Point& _B) {
double a, b, c, u, v;
a = _B.y - _A.y;
b = _A.x - _B.x;
c = _B.x * _A.y - _A.x * _B.y;
u = fabs(a * _p.x + b * _p.y + c);
v = fabs(a * _q.x + b * _q.y + c);
return Point((_p.x * v + _q.x * u) / (u + v),
(_p.y * v + _q.y * u) / (u + v));
}
Polygon Cut_Polygon(const Point& _a, const Point& _b) {
Polygon ans;
for (int i = 0; i < (int)vp.size(); i++) {
double left1 = Cross_Product(Vec(_a, _b), Vec(_a, vp[i])), left2 = 0;
if (i != (int)vp.size() - 1)
left2 = Cross_Product(Vec(_a, _b), Vec(_a, vp[i + 1]));
if (left1 > -EPS) ans.Add(vp[i]);
if (left1 * left2 < -EPS)
ans.Add(Line_Intersect_Seg(vp[i], vp[i + 1], _a, _b));
}
if (!ans.vp.empty() && !(ans.vp.back() == ans.vp.front()))
ans.Add(ans.vp.front());
return ans;
}
};
vector<Point> Convex_Hull(vector<Point> vp) {
int i, j, n = (int)vp.size();
if (n <= 3) {
if (!(vp[0] == vp[n - 1])) vp.push_back(vp[0]);
return vp;
}
int P0 = 0;
for (i = 1; i < n; i++)
if (vp[i].y < vp[P0].y || (vp[i].y == vp[P0].y && vp[i].x > vp[P0].x))
P0 = i;
swap(vp[0], vp[P0]);
sort(vp.begin() + 1, vp.end(), [vp](const Point& _a, const Point& _b) {
if (Collinear(vp[0], _a, _b))
return Euclidean_Distance(vp[0], _a) < Euclidean_Distance(vp[0], _b);
double d1x = _a.x - vp[0].x, d1y = _a.y - vp[0].y;
double d2x = _b.x - vp[0].x, d2y = _b.y - vp[0].y;
return (atan2(d1y, d1x) - atan2(d2y, d2x)) < 0;
});
vector<Point> ans;
ans.push_back(vp[n - 1]);
ans.push_back(vp[0]);
ans.push_back(vp[1]);
i = 2;
while (i < n) {
j = (int)ans.size() - 1;
if (Left_Of_Line(vp[i], ans[j - 1], ans[j]))
ans.push_back(vp[i++]);
else
ans.pop_back();
}
return ans;
}
double Area_Of_Polygon(const vector<Point> vertices) {
double sum = 0.;
for (int i = 0; i < vertices.size(); i++)
sum += Cross_Product(vertices[i], vertices[(i + 1) % vertices.size()]);
return abs(sum) / 2.0;
}
int n;
Point P;
vector<Point> p;
double Process() {
double R = 0, r = Distance_To_Line_Segment(P, p[0], p.back());
for (auto x : p) R = max(R, Euclidean_Distance(x, P));
for (int i = 1; i < n; i++)
r = min(r, Distance_To_Line_Segment(P, p[i - 1], p[i]));
return PI * (R * R - r * r);
}
void Output() {
double ans = Process();
cout << fixed << setprecision(12) << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
while (cin >> n) {
cin >> P;
p.resize(n);
for (int i = 0; i < n; i++) cin >> p[i];
Output();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int max_n = 100000;
const double eps = 1e-9;
const double pi = atan2(0, -1);
int xs[max_n];
int ys[max_n];
double d2(double x1, double y1, double x2, double y2) {
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}
double d2_seg(double x, double y, double x1, double y1, double x2, double y2) {
double a = (x2 - x1);
double b = (y2 - y1);
double t = (-1.0) * ((a * (x1 - x) + b * (y1 - y)) / (a * a + b * b));
if (fabs(t - 0.0) < eps) {
return d2(x, y, x1, y1);
}
if (fabs(t - 1.0) < eps) {
return d2(x, y, x2, y2);
}
if (t - 0.0 > -eps && t - 1.0 < eps) {
double qx = x1 + a * t, qy = y1 + b * t;
return d2(x, y, qx, qy);
}
return min(d2(x, y, x1, y1), d2(x, y, x2, y2));
}
int main() {
int N, px, py;
scanf("%d %d %d", &N, &px, &py);
for (int i = 0; i < N; i++) {
scanf("%d %d", &xs[i], &ys[i]);
}
double farest_d2 = d2(px, py, xs[0], ys[0]);
double nearest_d2 = d2_seg(px, py, xs[N - 1], ys[N - 1], xs[0], ys[0]);
for (int i = 0; i < N; i++) {
double dis2 = d2(px, py, xs[i], ys[i]);
if (dis2 > farest_d2) farest_d2 = dis2;
}
for (int i = 0; i + 1 < N; i++) {
double dis2_seg = d2_seg(px, py, xs[i], ys[i], xs[i + 1], ys[i + 1]);
if (dis2_seg < nearest_d2) nearest_d2 = dis2_seg;
}
double area = pi * (farest_d2 - nearest_d2);
printf("%.10lf\n", area);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct pt {
double x, y;
} ar[100010];
double md(pt v, pt w, pt p) {
const double l2 = (w.x - v.x) * (w.x - v.x) + (w.y - v.y) * (w.y - v.y);
if (l2 == 0.0)
return sqrt((p.x - v.x) * (p.x - v.x) + (p.y - v.y) * (p.y - v.y));
const double t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
if (t < 0.0)
return sqrt((p.x - v.x) * (p.x - v.x) + (p.y - v.y) * (p.y - v.y));
else if (t > 1.0)
return sqrt((p.x - w.x) * (p.x - w.x) + (p.y - w.y) * (p.y - w.y));
struct pt projection;
projection.x = v.x + t * (w.x - v.x);
projection.y = v.y + t * (w.y - v.y);
return sqrt((p.x - projection.x) * (p.x - projection.x) +
(p.y - projection.y) * (p.y - projection.y));
}
int main() {
double dma = -1.0, dmi = 1e20;
int n;
scanf("%d", &n);
int px, py;
scanf("%d %d", &px, &py);
double PX = px, PY = py;
pt P;
P.x = PX;
P.y = PY;
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
double X = x, Y = y;
ar[i].x = X;
ar[i].y = Y;
dma = max(dma, (X - PX) * (X - PX) + (Y - PY) * (Y - PY));
if (i != 0)
dmi = min(dmi, md(ar[i], ar[i - 1], P) * md(ar[i], ar[i - 1], P));
}
dmi = min(dmi, md(ar[n - 1], ar[0], P) * md(ar[n - 1], ar[0], P));
printf("%.10lf\n", acos(-1.0) * (dma - dmi));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
struct point {
double x, y;
} p[100010], o;
struct line {
double k, b;
};
inline double dis(point a, point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
inline line make_line(point a, point b) {
line ret;
ret.k = (a.y - b.y) / (a.x - b.x);
ret.b = a.y - a.x * ret.k;
return ret;
}
inline double dis_ltop(point a, line b) {
return abs(b.k * a.x + -1 * a.y + b.b) / sqrt(1 + b.k * b.k);
}
inline double dis_ltop(point a, point p, point q) {
double d1 = (q.x - p.x) * (a.x - p.x) + (q.y - p.y) * (a.y - p.y);
if (d1 <= 0) return dis(a, p);
double d2 = dis(p, q);
if (d1 >= d2) return dis(a, q);
double r = d1 / d2;
point pp;
pp.x = p.x + (q.x - p.x) * r;
pp.y = p.y + (q.y - p.y) * r;
return dis(pp, a);
}
double mx = -1e18, mn = 1e18;
int main() {
cin >> n >> o.x >> o.y;
for (int i = 1; i <= n; ++i) {
scanf("%lf%lf", &p[i].x, &p[i].y);
double r = dis(p[i], o);
mx = max(mx, r);
mn = min(mn, r);
}
for (int i = 1; i <= n; ++i) {
int j = i + 1;
if (j > n) j -= n;
mn = min(mn, dis_ltop(o, p[i], p[j]));
}
printf("%.18lf", (mx - mn) * acos(-1));
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
double x, y;
} a[101000], o;
double lenmin = 20000000000, lenmax = 0, ans;
double dis(node a, node b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double get_dis(node a, node b, node c) {
double alen = dis(b, c);
double blen = dis(a, c);
double clen = dis(a, b);
if (alen * alen + clen * clen <= blen * blen) {
return alen;
}
if (blen * blen + clen * clen <= alen * alen) {
return blen;
}
double s = abs((a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x));
return s / clen;
}
void init() {
cin >> n >> o.x >> o.y;
for (int i = 0; i < n; i++) {
cin >> a[i].x >> a[i].y;
lenmax = max(lenmax, dis(a[i], o));
}
for (int i = 0; i < n; i++) {
int j = (i + 1) % n;
lenmin = min(lenmin, get_dis(a[i], a[j], o));
}
printf("%.10f\n", acos(-1.0) * (lenmax * lenmax - lenmin * lenmin));
}
int main() {
init();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const bool testing = false;
double pDistance(double x, double y, 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;
}
void program() {
int n;
cin >> n;
double x, y;
cin >> x >> y;
double min = 10e14;
double max = 0;
double fa, fb, pa, pb;
double a, b, c;
cin >> fa >> fb;
pa = fa;
pb = fb;
for (int i = 1; i < n; i++) {
cin >> a >> b;
c = pDistance(x, y, pa, pb, a, b);
if (c < min) min = c;
c = (x - a) * (x - a) + (y - b) * (y - b);
if (c > max) max = c;
pa = a;
pb = b;
}
c = pDistance(x, y, fa, fb, a, b);
if (c < min) min = c;
c = (x - fa) * (x - fa) + (y - fb) * (y - fb);
if (c > max) max = c;
double r = max - min;
r *= 3.141592653589793238463;
cout.precision(20);
cout << r << endl;
}
int main() {
if (!testing) {
program();
return 0;
}
FILE* fin = NULL;
fin = fopen("in.txt", "w+");
fprintf(fin, "4 0 0\n1 1\n-1 1\n-1 2\n1 2\n");
fclose(fin);
freopen("in.txt", "r", stdin);
printf("test case(1) => expected : \n");
printf("12.566370614359172464\n");
printf("test case(1) => founded : \n");
program();
fin = fopen("in.txt", "w+");
fprintf(fin, "4 1 -1\n0 0\n1 2\n2 0\n1 1\n");
fclose(fin);
freopen("in.txt", "r", stdin);
printf("test case(2) => expected : \n");
printf("21.991148575128551812\n");
printf("test case(2) => founded : \n");
program();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << "[ " << *it << " = " << a << " ] ";
err(++it, args...);
}
double find_dis(double x, double y, double a, double b) {
return (x - a) * (x - a) + (y - b) * (y - b);
}
double find_height(double x, double y, double ax, double ay, double bx,
double by) {
double area = abs(x * ay + ax * by + bx * y - ax * y - bx * ay - x * by);
double base = sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
double a = find_dis(x, y, ax, ay);
double b = find_dis(x, y, bx, by);
if (a >= b + base * base or b >= a + base * base) return min(a, b);
double h = area / base;
return h * h;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, i;
double px, py, maxi = DBL_MIN, mini = DBL_MAX;
cin >> n >> px >> py;
vector<pair<double, double> > v(n + 1);
for (i = 0; i < n; i++) {
cin >> v[i].first >> v[i].second;
maxi = max(maxi, find_dis(px, py, v[i].first, v[i].second));
}
v[n] = v[0];
for (i = 0; i < n; i++) {
mini = min(mini, find_height(px, py, v[i].first, v[i].second,
v[i + 1].first, v[i + 1].second));
}
cout << setprecision(15) << fixed << acos(-1) * (maxi - mini) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
int N, X, Y;
double R, r = 2e18;
struct data {
int x, y;
} A[MAX_N + 5];
int main() {
int i;
long long a, b, c;
double d;
scanf("%d %d %d", &N, &X, &Y);
for (i = 1; i <= N; i++) scanf("%d %d", &A[i].x, &A[i].y);
A[N + 1] = A[1];
for (i = 1; i <= N; i++) {
R = max(R, (double)(A[i].x - X) * (A[i].x - X) +
(double)(A[i].y - Y) * (A[i].y - Y));
}
for (i = 1; i <= N; i++) {
r = min(r, (double)(A[i].x - X) * (A[i].x - X) +
(double)(A[i].y - Y) * (A[i].y - Y));
}
for (i = 1; i <= N; i++) {
if (A[i].x == A[i + 1].x) {
a = 1, b = 0, c = A[i].x;
} else if (A[i].y == A[i + 1].y) {
a = 0, b = -1, c = A[i].y;
} else {
a = (A[i + 1].y - A[i].y);
b = -(A[i + 1].x - A[i].x);
c = -(a * A[i].x + b * A[i].y);
}
d = (double)(a * X + b * Y + c) * (a * X + b * Y + c) /
(double)(a * a + b * b);
if ((double)(A[i].x - X) * (A[i].x - X) +
(double)(A[i].y - Y) * (A[i].y - Y) <
(double)(A[i + 1].x - X) * (A[i + 1].x - X) +
(double)(A[i + 1].y - Y) * (A[i + 1].y - Y)) {
if ((double)(A[i + 1].x - X) * (A[i + 1].x - X) +
(double)(A[i + 1].y - Y) * (A[i + 1].y - Y) - d >
(double)(A[i + 1].x - A[i].x) * (A[i + 1].x - A[i].x) +
(double)(A[i + 1].y - A[i].y) * (A[i + 1].y - A[i].y))
continue;
} else {
if ((double)(A[i].x - X) * (A[i].x - X) +
(double)(A[i].y - Y) * (A[i].y - Y) - d >
(double)(A[i + 1].x - A[i].x) * (A[i + 1].x - A[i].x) +
(double)(A[i + 1].y - A[i].y) * (A[i + 1].y - A[i].y))
continue;
}
r = min(r, d);
}
printf("%.12f", (R - r) * 3.14159265358979);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
} p[100005], t;
int n;
double dis(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double dot(point a, point b) { return a.x * b.x + a.y * b.y; }
double len(point a) { return sqrt(dot(a, a)); }
double point_to_segment(point a, point b, point c) {
point v1, v2, v3;
v1.x = c.x - b.x;
v1.y = c.y - b.y;
v2.x = a.x - b.x;
v2.y = a.y - b.y;
v3.x = a.x - c.x;
v3.y = a.y - c.y;
if (dot(v1, v2) < 0)
return len(v2);
else if (dot(v1, v3) > 0)
return len(v3);
else
return fabs((v1.x * v2.y - v2.x * v1.y) / len(v1));
}
int main() {
scanf("%d", &n);
scanf("%lf%lf", &t.x, &t.y);
for (int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
p[n].x = p[0].x;
p[n].y = p[0].y;
double Max = 0;
double Min = 1000000000.0;
for (int i = 0; i < n; i++) {
Max = max(Max, dis(t, p[i]));
Min = min(Min, point_to_segment(t, p[i], p[i + 1]));
}
printf("%0.10f\n", Max * Max * acos(-1.0) - Min * Min * acos(-1.0));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
const int MM = 998244353;
const long double PI = acos(-1);
template <typename T, typename U>
static inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
static inline void amax(T &x, U y) {
if (x < y) x = y;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << '(' << p.first << "," << p.second << ')';
}
struct Point {
long long x, y;
Point() {}
Point(long long x_, long long y_) {
x = x_;
y = y_;
}
friend istream &operator>>(istream &i, Point &p) { return i >> p.x >> p.y; }
double dis(Point &p) { return sqrt(pow(p.x - x, 2) + pow(p.y - y, 2)); }
long long cross(Point r) { return x * r.y - y * r.x; }
};
Point operator-(Point &l, Point &r) { return Point(l.x - r.x, l.y - r.y); }
int _runtimeTerror_() {
int n;
Point P;
cin >> n >> P;
vector<Point> p(n);
for (int i = 0; i < n; ++i) cin >> p[i];
double max = 0, min = 1e9;
for (int i = 0; i < n; ++i) {
amax(max, P.dis(p[i]));
amin(min, P.dis(p[i]));
Point d = p[i] - p[(i + 1) % n];
swap(d.x, d.y);
d.x *= -1;
if (((p[i] - P).cross(d) > 0 ? 1 : -1) *
((p[(i + 1) % n] - P).cross(d) > 0 ? 1 : -1) <
0)
amin(min, abs((p[i] - P).cross(p[(i + 1) % n] - p[i]) /
p[i].dis(p[(i + 1) % n])));
}
cout << fixed << setprecision(20);
cout << acos(-1) * (max * max - min * min);
return 0;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) _runtimeTerror_();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using pi = pair<int, int>;
using vs = vector<string>;
using vpi = vector<pi>;
using ll = long long int;
template <typename T>
string tostr(T x) {
ostringstream oss;
oss << x;
return oss.str();
}
template <typename T1, typename T2, typename T3>
T1 modpow(T1 a, T2 p, T3 mod) {
T1 ret = 1;
a %= mod;
for (; p > 0; p /= 2) {
if (p & 1) ret = 1ll * ret * a % mod;
a = 1ll * a * a % mod;
}
return ret;
}
int dx[]{-1, 0, 1, 0, 1, 1, -1, -1};
int dy[]{0, -1, 0, 1, 1, -1, 1, -1};
constexpr auto PI = 3.14159265358979323846L;
constexpr auto oo = numeric_limits<ll>::max() / 2 - 10;
constexpr auto eps = 1e-7;
constexpr auto mod = 1000000007;
constexpr int mx = 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 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;
}
long double DistancePointSegment(PT a, PT b, PT c) {
return sqrt(dist2(c, ProjectPointSegment(a, b, c)));
}
int main() {
int px, py, n, x, y;
long double r1, r2;
r1 = oo, r2 = -oo;
scanf("%d %d %d", &n, &px, &py);
long double ans;
PT last(-1, -1), cur, fs;
for (auto i = 0, _i = (n); i < _i; ++i) {
scanf("%d %d", &x, &y);
ll dx = x - px, dy = y - py;
r2 = max(r2, sqrt(1.0L * dx * dx + 1.0L * dy * dy));
cur = PT(x, y);
if (i) {
r1 = min(r1, DistancePointSegment(cur, last, PT(px, py)));
} else {
fs = cur;
}
last = cur;
}
r1 = min(r1, DistancePointSegment(fs, last, PT(px, py)));
;
ans = PI * (r2 * r2 - r1 * r1);
std::cout << std::fixed;
std::cout << std::setprecision(9);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979311599796346854;
struct point {
double x, y;
};
struct vect {
double x, y;
};
bool isABCSharp(point a, point b, point c) {
vect ba = {a.x - b.x, a.y - b.y};
vect bc = {c.x - b.x, c.y - b.y};
double scalar = ba.x * bc.x + ba.y * bc.y;
return scalar > 0;
}
double dist(point p, point a, point b) {
double x0 = p.x, y0 = p.y, x1 = a.x, y1 = a.y, x2 = b.x, y2 = b.y, x, y;
x = (x0 * (x1 - x2) * (x1 - x2) + y0 * (y1 - y2) * (x1 - x2) -
(y1 - y2) * (x1 * y2 - x2 * y1)) /
((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
y = (x0 * (x1 - x2) * (y1 - y2) + y0 * (y1 - y2) * (y1 - y2) +
(x1 - x2) * (x1 * y2 - x2 * y1)) /
((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
return sqrt((x - x0) * (x - x0) + (y - y0) * (y - y0));
}
int main() {
int n;
cin >> n;
point p;
cin >> p.x >> p.y;
vector<point> points(n);
for (int i = 0; i < n; i++) cin >> points[i].x >> points[i].y;
double far = 0, close = numeric_limits<double>::infinity();
for (int i = 0; i < n; i++) {
point a = points[i], b = points[(i + 1) % n];
double min_dist, max_dist;
if (isABCSharp(p, a, b) && isABCSharp(p, b, a))
min_dist = dist(p, a, b);
else
min_dist =
min(sqrt((p.x - a.x) * (p.x - a.x) + (p.y - a.y) * (p.y - a.y)),
sqrt((p.x - b.x) * (p.x - b.x) + (p.y - b.y) * (p.y - b.y)));
max_dist = max(sqrt((p.x - a.x) * (p.x - a.x) + (p.y - a.y) * (p.y - a.y)),
sqrt((p.x - b.x) * (p.x - b.x) + (p.y - b.y) * (p.y - b.y)));
far = max(far, max_dist);
close = min(close, min_dist);
}
cout << setprecision(30) << PI * (far * far - close * close) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
double dist(double x1, double y1, double x2, double y2) {
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
int main() {
long long n;
double i, j, x1, y1, x, y, curx, cury, mind, maxd;
cin >> n >> i >> j;
cin >> x1 >> y1;
curx = x1;
cury = y1;
mind = dist(i, j, x1, y1);
maxd = dist(i, j, x1, y1);
for (long long k = 1; k < n; k++) {
cin >> x >> y;
mind = min(dist(i, j, x, y), mind);
if (((y - j) * (y - cury) + (x - curx) * (x - i)) *
((cury - j) * (y - cury) + (x - curx) * (curx - i)) <
0)
mind = min(abs((j - cury) * (x - curx) - (y - cury) * (i - curx)) /
sqrt((x - curx) * (x - curx) + (y - cury) * (y - cury)),
mind);
maxd = max(dist(i, j, x, y), maxd);
curx = x;
cury = y;
}
if (((y1 - j) * (y1 - cury) + (x1 - curx) * (x1 - i)) *
((cury - j) * (y1 - cury) + (x1 - curx) * (curx - i)) <
0)
mind = min(abs((j - cury) * (x1 - curx) - (y1 - cury) * (i - curx)) /
sqrt((x1 - curx) * (x1 - curx) + (y1 - cury) * (y1 - cury)),
mind);
cout << fixed << setprecision(18) << acos(-1.0) * (maxd * maxd - mind * mind);
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const double PI = 3.14159265358979323846;
const double maxN = 1e10;
double sqr(double a) { return a * a; }
struct Point {
double x, y;
long long int ind;
Point(double x0 = 0, double y0 = 0, long long int ind = 0) {
this->x = x0;
this->y = y0;
this->ind = ind;
}
};
bool operator==(const Point& a, const Point& b) {
return a.x == b.x && a.y == b.y;
}
bool operator<(const Point& a, const Point& b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
struct Vector {
double x, y;
long long int ind;
Vector(double x0 = 0, double y0 = 0) {
this->x = x0;
this->y = y0;
}
Vector(const Point& A, const Point& B, long long int ind = 0) {
this->x = B.x - A.x;
this->y = B.y - A.y;
this->ind = ind;
}
double len() { return sqrt(x * x + y * y); }
double angle() const { return atan2(y, x); }
};
struct Circle {
double x, y, r;
Circle(double x0 = 0, double y0 = 0, double r0 = 0) {
this->x = x0;
this->y = y0;
this->r = r0;
}
Point get_center() { return Point(this->x, this->y); }
double getSubS(double ang) { return ang * r; }
};
bool operator==(Circle& a, Circle& b) {
return a.x == b.x && a.y == b.y && a.r == b.r;
}
Vector operator/(Vector A, double d) { return Vector(A.x / d, A.y / d); };
Vector operator*(Vector A, double d) { return Vector(A.x * d, A.y * d); };
Point operator+(Point A, Vector B) { return Point(A.x + B.x, A.y + B.y); }
struct Line {
double a, b, c;
Line(double a0 = 0, double b0 = 0, double c0 = 0) {
this->a = a0;
this->b = b0;
this->c = c0;
}
Line(Point& A, Point& B) {
Vector AB(A, B);
b = -AB.x;
a = AB.y;
c = -a * A.x - b * A.y;
}
Line(Point& A, Vector& C) {
Point B = A + C;
Line(A, B);
}
Vector normal() { return Vector(a, b); }
Point getPoint() {
double x = -(a * c) / (a * a + b * b);
double y = -(b * c) / (a * a + b * b);
return Point(x, y);
}
double get(Point& A) { return a * A.x + b * A.y + c; }
double perp_sz(const Point& C) {
return (a * C.x + b * C.y + c) / sqrt(a * a + b * b);
}
Point proection(const Point& A) {
double d = perp_sz(A);
Vector n = normal();
n = n / n.len();
Vector n1 = n * d, n2 = n * (-d);
Point A1 = A + n1, A2 = A + n2;
if (get(A1) == 0)
return A1;
else
return A2;
}
};
struct Ray {
Point A, B;
Ray(){};
Ray(Point& A, Point& B) {
this->A = A;
this->B = B;
}
};
istream& operator>>(istream& in, Circle& P) { return in >> P.x >> P.y >> P.r; }
istream& operator>>(istream& in, Point& P) { return in >> P.x >> P.y; }
istream& operator>>(istream& in, Vector& P) { return in >> P.x >> P.y; }
istream& operator>>(istream& in, Line& P) { return in >> P.a >> P.b >> P.c; }
ostream& operator<<(ostream& out, Point P) {
out.precision(20);
return out << P.x << " " << P.y;
}
ostream& operator<<(ostream& out, Vector P) {
out.precision(20);
return out << P.x << " " << P.y << endl;
}
ostream& operator<<(ostream& out, Line P) {
out.precision(20);
return out << P.a << " " << P.b << " " << P.c << endl;
}
double dot_product(const Vector& A, const Vector& B) {
return A.x * B.x + A.y * B.y;
}
double cross_product(const Vector& A, const Vector& B) {
return A.x * B.y - A.y * B.x;
}
double angle(Vector A, Vector B) {
return fabs(atan2(cross_product(A, B), dot_product(A, B)));
}
Vector ort(Vector A) { return Vector(-A.y, A.x); }
bool one(double a, double b) { return a * b >= 0; }
Vector rotate_v(const Vector& A, double angle_rad) {
return Vector((A.x * cos(angle_rad) - A.y * sin(angle_rad)),
(A.x * sin(angle_rad) + A.y * cos(angle_rad)));
}
Point zero = Point(0, 0);
vector<Point> intersect(Line& a, Line& b) {
if (cross_product(a.normal(), b.normal()) == 0) return {};
double x = (b.c * a.b - b.b * a.c) / (b.b * a.a - a.b * b.a);
double y = (b.c * a.a - a.c * b.a) / (a.b * b.a - b.b * a.a);
return {Point(x, y)};
}
vector<Point> intersect(Circle& c, Line& a) {
if (a.perp_sz(c.get_center()) > c.r)
return {};
else if (a.perp_sz(c.get_center()) == c.r)
return {a.proection(c.get_center())};
else {
Point S = a.proection(c.get_center());
Vector n = ort(a.normal());
n = n / n.len();
double sz = sqrt(sqr(c.r) - sqr(a.perp_sz(c.get_center())));
Vector n1 = n * sz;
Vector n2 = n * (-sz);
return {S + n1, S + n2};
}
}
vector<Point> intersect(Circle& a, Circle& b) {
Vector AB(a.get_center(), b.get_center());
if (AB.len() > a.r + b.r)
return {};
else {
double la = 2 * a.x - 2 * b.x;
double lb = 2 * a.y - 2 * b.y;
double lc = sqr(b.x) + sqr(b.y) - sqr(b.r) - sqr(a.x) - sqr(a.y) + sqr(a.r);
Line l(la, lb, lc);
return intersect(a, l);
}
}
bool cmpAndrew(const Point& a, const Point& b) {
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
bool cw(Point a, Point b, Point c) {
return cross_product(Vector(b, a), Vector(b, c)) > 0;
}
bool ccw(Point a, Point b, Point c) {
return cross_product(Vector(b, a), Vector(b, c)) < 0;
}
vector<Point> Andrew(vector<Point>& points) {
sort(points.begin(), points.end(), cmpAndrew);
vector<Point> up, down;
up.push_back(points[0]);
down.push_back(points[0]);
Point p1 = points[0], p2 = points.back();
long long int n = (long long int)points.size();
for (long long int i = 1; i < n; i++) {
if (i == n - 1 || cw(p1, points[i], p2)) {
while (up.size() >= 2 &&
!cw(up[up.size() - 2], up[up.size() - 1], points[i])) {
up.pop_back();
}
up.push_back(points[i]);
}
if (i == n - 1 || ccw(p1, points[i], p2)) {
while (down.size() >= 2 &&
!ccw(down[down.size() - 2], down[down.size() - 1], points[i])) {
down.pop_back();
}
down.push_back(points[i]);
}
}
vector<Point> convexHall;
for (auto i : down) convexHall.push_back(i);
for (long long int i = (long long int)up.size() - 2; i >= 1; i--)
convexHall.push_back(up[i]);
return convexHall;
}
Point first;
struct node {
Point now, up, down;
node(Point& now) { this->now = now; }
node(Point& down, Point& now) {
this->down = down;
this->now = now;
}
};
bool cmpGraham(const Point& A, const Point& B) {
Vector OA(first, A);
Vector OB(first, B);
return cross_product(OA, OB) > 0 ||
(cross_product(OA, OB) == 0 && OA.len() < OB.len());
}
vector<node> Graham(vector<Point>& points, unordered_set<long long int>& ind) {
first = Point(1e10, 1e10);
long long int n = (long long int)points.size();
for (long long int i = 0; i < n; i++) {
if (points[i] < first) first = points[i];
}
sort(points.begin(), points.end(), cmpGraham);
vector<node> convex = {node(points[0]), node(points[0], points[1])};
convex[0].up = points[1];
for (long long int i = 2; i < n; i++) {
long long int l = (long long int)convex.size();
Vector oldV(convex[l - 2].now, convex[l - 1].now),
newV(convex[l - 1].now, points[i]);
while (cross_product(oldV, newV) < 0) {
convex.pop_back();
l = (long long int)convex.size();
oldV = Vector(convex[l - 2].now, convex[l - 1].now);
newV = Vector(convex[l - 1].now, points[i]);
}
Point down = convex.back().now;
convex.back().up = points[i];
if (cross_product(oldV, newV) == 0) convex.pop_back();
convex.push_back(node(down, points[i]));
}
convex[0].down = convex.back().now;
convex.back().up = convex[0].now;
for (auto i : convex) ind.insert(i.now.ind);
return convex;
}
vector<Point> convexHall;
vector<Vector> up, down;
bool cmpV(const Vector& a, const Vector& b) { return cross_product(a, b) > 0; }
void preTangents(vector<Point>& points) {
convexHall = Andrew(points);
for (long long int i = 0; i < convexHall.size(); i++) {
Point A = convexHall[i], B = convexHall[(i + 1) % convexHall.size()];
Vector AB(A, B, i);
if (AB.angle() >= 0 || fabs(AB.angle()) == PI)
up.push_back(AB);
else
down.push_back(AB);
}
sort(up.begin(), up.end(), cmpV);
sort(down.begin(), down.end(), cmpV);
}
vector<Point> tangents(Line& l) {
if (convexHall.size() == 1)
return {convexHall[0], convexHall[0]};
else if (convexHall.size() == 2)
return convexHall;
else {
Vector n1 = ort(l.normal());
Vector n2 = n1 * -1;
long long int ind1, ind2;
if (n1.angle() >= 0 || fabs(n1.angle()) == PI) {
auto it = lower_bound(up.begin(), up.end(), n1, cmpV);
if (it != up.end())
ind1 = (*it).ind;
else
ind1 = down[0].ind;
} else {
auto it = lower_bound(down.begin(), down.end(), n1, cmpV);
if (it != down.end())
ind1 = (*it).ind;
else
ind1 = up[0].ind;
}
if (n2.angle() >= 0 || fabs(n2.angle()) == PI) {
auto it = lower_bound(up.begin(), up.end(), n2, cmpV);
if (it != up.end())
ind2 = (*it).ind;
else
ind2 = down[0].ind;
} else {
auto it = lower_bound(down.begin(), down.end(), n2, cmpV);
if (it != down.end())
ind2 = (*it).ind;
else
ind2 = up[0].ind;
}
return {convexHall[ind1], convexHall[ind2]};
}
}
bool intersect_1(double a, double b, double c, double d) {
if (a > b) swap(a, b);
if (c > d) swap(c, d);
return max(a, c) <= min(b, d);
}
bool intersect(Point& A, Point& B, Point& C, Point& D) {
Vector AB(A, B), BA(B, A), AC(A, C), AD(A, D), BC(B, C), BD(B, D);
Vector CD(C, D), DC(D, C), DA(D, A), DB(D, B), CA(C, A), CB(C, B);
if (cross_product(AB, AC) == 0 && cross_product(AB, AD) == 0) {
if (intersect_1(A.x, B.x, C.x, D.x) && intersect_1(A.y, B.y, C.y, D.y))
return true;
else
return false;
}
bool ans = (!one(cross_product(AB, AC), cross_product(AB, AD)) &&
!one(cross_product(CD, CA), cross_product(CD, CB)));
return ans;
}
double dist(Point A, Point B) {
Vector AB(A, B);
return AB.len();
}
double dist(Point A, Point B, Point C) {
Vector BC(B, C), CB(C, B), BA(B, A), CA(C, A);
Line l(B, C);
if (dot_product(BC, BA) >= 0 && dot_product(CB, CA) >= 0)
return fabs(l.perp_sz(A));
else if (dot_product(BC, BA) < 0)
return dist(A, B);
else
return dist(A, C);
}
double dist(Point A, Ray Q) {
Point B = Q.A, C = Q.B;
Vector BC(B, C), BA(B, A);
Line l(B, C);
if (dot_product(BC, BA) < 0)
return dist(A, B);
else
return fabs(l.perp_sz(A));
}
double dist(Point A, Line L) { return fabs(L.perp_sz(A)); }
double dist(Point A, Point B, Point C, Point D) {
if (intersect(A, B, C, D))
return 0;
else
return min({dist(A, C, D), dist(B, C, D), dist(C, A, B), dist(D, A, B)});
}
double dist(Point A, Point B, Ray Q) {
Point C = Q.A, D = Q.B;
Vector CD(C, D);
CD = CD * maxN;
D = D + CD;
return dist(A, B, C, D);
}
double dist(Point A, Point B, Line L) {
Point C = L.getPoint();
Vector n = ort(L.normal());
Vector n1 = n * maxN, n2 = n * (-maxN);
C = C + n1;
Point D = C + n2;
return dist(A, B, C, D);
}
double dist(Ray Q1, Ray Q2) {
Point A = Q1.A, B = Q1.B, C = Q2.A, D = Q2.B;
Vector AB(A, B), CD(C, D);
AB = AB * maxN;
CD = CD * maxN;
B = B + AB;
D = D + CD;
return dist(A, B, C, D);
}
double dist(Ray Q, Line L) {
Point A = Q.A, B = Q.B, C = L.getPoint();
Vector AB(A, B);
AB = AB * maxN;
B = B + AB;
Vector n = ort(L.normal());
Vector n1 = n * maxN, n2 = n * (-maxN);
C = C + n1;
Point D = C + n2;
return dist(A, B, C, D);
}
double dist(Line L1, Line L2) {
Point A = L1.getPoint();
Vector n = ort(L1.normal());
Vector n1 = n * maxN, n2 = n * (-maxN);
A = A + n1;
Point B = A + n2;
Point C = L2.getPoint();
Vector m = ort(L2.normal());
Vector m1 = m * maxN, m2 = m * (-maxN);
C = C + m1;
Point D = C + m2;
return dist(A, B, C, D);
}
signed main() {
Point P;
long long int n;
cin >> n >> P;
vector<Point> a(n);
vector<double> b;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
b.push_back(dist(P, a[i]));
}
for (long long int i = 0; i < n; i++) {
Point A = a[i], B = a[(i + 1) % n];
b.push_back(dist(P, A, B));
}
sort(b.begin(), b.end());
cout.precision(20);
cout << PI * (b.back() * b.back() - b.front() * b.front()) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct myk {
double x;
double y;
double distance;
};
myk a[100000 + 10];
int n, origin_x, origin_y;
double xiao, da;
double juli(double xx1, double yy1, double xx2, double yy2) {
double xx0 = origin_x, yy0 = origin_y;
double temp, temp2;
temp = sqrt((xx2 - xx1) * (xx2 - xx1) + (yy2 - yy1) * (yy2 - yy1));
temp2 = (xx1 - xx0) * (yy2 - yy0) - (yy1 - yy0) * (xx2 - xx0);
temp2 = fabs(temp2);
return (temp2 / temp);
}
bool isruijiao(double xx1, double yy1, double xx2, double yy2) {
int status = 1;
double xx0 = origin_x, yy0 = origin_y;
if ((xx0 - xx1) * (xx2 - xx1) + (yy0 - yy1) * (yy2 - yy1) < 0) status = 0;
if ((xx1 - xx2) * (xx0 - xx2) + (yy1 - yy2) * (yy0 - yy2) < 0) status = 0;
return status;
}
int main(void) {
cin >> n >> origin_x >> origin_y;
xiao = 1000000000;
da = 0;
for (int i = 0; i < n; i++) {
scanf("%lf%lf", &a[i].x, &a[i].y);
a[i].distance = sqrt(((a[i].x - origin_x) * (a[i].x - origin_x)) +
((a[i].y - origin_y) * (a[i].y - origin_y)));
xiao = min(xiao, a[i].distance);
da = max(da, a[i].distance);
}
for (int i = 1; i < n; i++) {
if (isruijiao(a[i - 1].x, a[i - 1].y, a[i].x, a[i].y))
xiao = min(xiao, juli(a[i - 1].x, a[i - 1].y, a[i].x, a[i].y));
}
if (isruijiao(a[0].x, a[0].y, a[n - 1].x, a[n - 1].y))
xiao = min(xiao, juli(a[0].x, a[0].y, a[n - 1].x, a[n - 1].y));
double temp = da * da - xiao * xiao;
printf("%.15lf", acos(-1) * temp);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::istream &operator>>(std::istream &i, pair<T, U> &p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream &operator>>(std::istream &i, vector<T> &t) {
for (auto &v : t) {
i >> v;
}
return i;
}
template <typename T>
std::ostream &operator<<(std::ostream &o, const vector<T> &t) {
if (t.empty()) o << '\n';
for (size_t i = 0; i < t.size(); ++i) {
o << t[i] << " \n"[i == t.size() - 1];
}
return o;
}
template <typename T, typename U>
std::ostream &operator<<(std::ostream &o, pair<T, U> &p) {
o << p.first << ' ' << p.second;
return o;
}
template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
bool in(T a, T b, T c) {
return a <= b && b < c;
}
unsigned int logceil(int first) {
return 8 * sizeof(int) - __builtin_clz(first);
}
namespace std {
template <typename T, typename U>
struct hash<pair<T, U>> {
hash<T> t;
hash<U> u;
size_t operator()(const pair<T, U> &p) const {
return t(p.first) ^ (u(p.second) << 7);
}
};
} // namespace std
template <typename T, typename F>
T bsh(T l, T h, const F &f) {
T r = -1, m;
while (l <= h) {
m = (l + h) / 2;
if (f(m)) {
l = m + 1;
r = m;
} else {
h = m - 1;
}
}
return r;
}
template <typename F>
double bshd(double l, double h, const F &f, double p = 1e-9) {
unsigned int r = 3 + (unsigned int)log2((h - l) / p);
while (r--) {
double m = (l + h) / 2;
if (f(m)) {
l = m;
} else {
h = m;
}
}
return (l + h) / 2;
}
template <typename T, typename F>
T bsl(T l, T h, const F &f) {
T r = -1, m;
while (l <= h) {
m = (l + h) / 2;
if (f(m)) {
h = m - 1;
r = m;
} else {
l = m + 1;
}
}
return r;
}
template <typename F>
double bsld(double l, double h, const F &f, double p = 1e-9) {
unsigned int r = 3 + (unsigned int)log2((h - l) / p);
while (r--) {
double m = (l + h) / 2;
if (f(m)) {
h = m;
} else {
l = m;
}
}
return (l + h) / 2;
}
template <typename T>
T gcd(T a, T b) {
if (a < b) swap(a, b);
return b ? gcd(b, a % b) : a;
}
template <typename T>
class vector2 : public vector<vector<T>> {
public:
vector2() {}
vector2(size_t a, size_t b, T t = T())
: vector<vector<T>>(a, vector<T>(b, t)) {}
};
template <typename T>
class vector3 : public vector<vector2<T>> {
public:
vector3() {}
vector3(size_t a, size_t b, size_t c, T t = T())
: vector<vector2<T>>(a, vector2<T>(b, c, t)) {}
};
template <typename T>
class vector4 : public vector<vector3<T>> {
public:
vector4() {}
vector4(size_t a, size_t b, size_t c, size_t d, T t = T())
: vector<vector3<T>>(a, vector3<T>(b, c, d, t)) {}
};
template <typename T>
class vector5 : public vector<vector4<T>> {
public:
vector5() {}
vector5(size_t a, size_t b, size_t c, size_t d, size_t e, T t = T())
: vector<vector4<T>>(a, vector4<T>(b, c, d, e, t)) {}
};
template <typename T>
struct bounded_priority_queue {
inline bounded_priority_queue(unsigned int X) : A(X), B(0), s(0) {}
inline void push(unsigned int L, T V) {
B = max(B, L);
A[L].push(V);
++s;
}
inline const T &top() const { return A[B].front(); }
inline void pop() {
--s;
A[B].pop();
while (B > 0 && A[B].empty()) --B;
}
inline bool empty() const { return A[B].empty(); }
inline void clear() {
s = B = 0;
for (auto &a : A) a = queue<T>();
}
inline unsigned int size() const { return s; }
private:
vector<queue<T>> A;
unsigned int B;
int s;
};
constexpr double PI = 3.14159265358979323846;
template <typename T>
struct Segment;
template <typename T>
struct Point : public pair<T, T> {
Point(T a = 0, T b = 0) : pair<T, T>(a, b) {}
Point(const pair<T, T> &p) : pair<T, T>(p.first, p.second) {}
Point(const Point<T> &p) = default;
Point<T> &operator=(const Point<T> &p) = default;
T squaredDistance(const Point<T> &o) const {
return Segment<T>{*this, o}.squaredLength();
}
double distance(const Point<T> &o) const {
return Segment<T>{*this, o}.length();
}
};
template <typename T>
ostream &operator<<(ostream &o, const Point<T> &p) {
o << p.first << ' ' << p.second;
return o;
}
template <typename T>
T ccw(const Point<T> &a, const Point<T> &b, const Point<T> &c) {
return (b.first - a.first) * (c.second - a.second) -
(b.second - a.second) * (c.first - a.first);
}
template <typename T>
T area(const Point<T> &a, const Point<T> &b, const Point<T> &c) {
return abs(ccw(a, b, c));
}
template <typename T>
double cosangle(const Point<T> &a, const Point<T> &b, const Point<T> &c) {
return ((b.first - a.first) * (c.first - a.first) +
(b.second - a.second) * (c.second - a.second)) /
a.distance(b) / a.distance(c);
}
template <typename T>
double angle(const Point<T> &a, const Point<T> &b, const Point<T> &c) {
return acos(cosangle(a, b, c));
}
template <typename T>
int orientation(const Point<T> &a, const Point<T> &b, const Point<T> &c) {
auto o = ccw(a, b, c);
return (o > 1e-6) - (o < -1e-6);
}
template <typename T>
bool collinear(const Point<T> &a, const Point<T> &b, const Point<T> &c) {
return orientation(a, b, c) == 0;
}
template <typename T>
struct Segment : public pair<Point<T>, Point<T>> {
using pair<Point<T>, Point<T>>::first;
using pair<Point<T>, Point<T>>::second;
explicit Segment(Point<T> a = {0, 0}, Point<T> b = {0, 0})
: pair<Point<T>, Point<T>>(a, b) {}
Segment(const Segment<T> &) = default;
Segment<T> &operator=(const Segment<T> &) = default;
inline T dx() const { return first.first - second.first; }
inline T dy() const { return first.second - second.second; }
T squaredLength() const { return dx() * dx() + dy() * dy(); }
double length() const { return sqrt(squaredLength()); }
bool contains(const Point<T> &q) const {
return collinear(first, q, second) &&
((q.first <= max(first.first, second.first) &&
q.first >= min(first.first, second.first)) ||
(q.second <= max(first.second, second.second) &&
q.second >= min(first.second, second.second)));
}
double distance(const Point<T> &p) const {
double u =
((p.first - second.first) * dx() + (p.second - second.second) * dy()) /
double(dx() * dx() + dy() * dy());
if (u > 1) u = 1;
if (u < 0) u = 0;
return Point<double>(p.first, p.second)
.distance({second.first + u * dx(), second.second + u * dy()});
}
bool intersect(const Segment<T> &s) const {
return (orientation(first, second, s.first) !=
orientation(first, second, s.second) &&
orientation(s.first, s.second, first) !=
orientation(s.first, s.second, second)) ||
contains(s.first) || contains(s.second) || s.contains(first) ||
s.contains(second);
}
};
template <typename T>
struct Line : public pair<Point<T>, Point<T>> {
using pair<Point<T>, Point<T>>::first;
using pair<Point<T>, Point<T>>::second;
Line(Point<T> a = {0, 0}, Point<T> b = {0, 0})
: pair<Point<T>, Point<T>>(a, b) {}
explicit Line(const Segment<T> &s)
: pair<Point<T>, Point<T>>(s.first, s.second) {}
Line(const Line<T> &p) = default;
Line<T> &operator=(const Line<T> &p) = default;
inline T dx() const { return first.first - second.first; }
inline T dy() const { return first.second - second.second; }
inline T c() const {
return first.second * second.first - first.first * second.second;
}
double distance(const Point<T> &p) const {
long long px = dx(), py = dy(), dL = px * px + py * py;
return abs(py * p.first - px * p.second + second.first * first.second -
second.second * first.first) /
sqrt(dL);
}
Point<double> project(const Point<T> &p) const {
double u =
((p.first - second.first) * dx() + (p.second - second.second) * dy()) /
double(dx() * dx() + dy() * dy());
return {second.first + u * dx(), second.second + u * dy()};
}
bool parallel(const Line<T> &l) const {
return abs(l.dx() * dy() - l.dy() * dx()) < 1e-6;
}
Point<double> intersection(const Line<T> &l) {
double det = l.dx() * dy() - l.dy() * dx();
if (abs(det) < 1e-6)
return {1e300, 1e300};
else {
double c1 = c(), c2 = l.c();
double first = -(c2 * dx() - l.dx() * c1) / det;
double second = -(-l.dy() * c1 + c2 * dy()) / det;
return {first, second};
}
};
};
template <typename T>
struct Circle {
Point<T> center;
T radius;
bool intersect(const Circle<T> &o) const {
return o.center.squaredDistance(center) <=
(radius + o.radius) * (radius + o.radius);
}
bool contains(const Point<T> &p) const {
return p.squaredDistance(center) <= radius * radius;
}
bool contains(const Circle<T> &o) const {
return radius >= o.radius && center.squaredDistance(center) <=
(radius - o.radius) * (radius - o.radius);
}
bool touches(const Circle<T> &o) const {
T dist = center.squaredDistance(center);
return dist == (radius - o.radius) * (radius - o.radius) ||
dist == (radius + o.radius) * (radius + o.radius);
}
};
template <typename T>
struct Polygon : public vector<Point<T>> {
using vector<Point<T>>::vector;
using vector<Point<T>>::at;
using vector<Point<T>>::front;
using vector<Point<T>>::back;
T doubleSignedArea() const {
if (this->empty()) return T(0);
T area = back().first * front().second - back().second * front().first;
for (int i = 0; i < this->size() - 1; ++i)
area += (at(i).first * at(i + 1).second - at(i + 1).first * at(i).second);
return area;
}
double circumference() const {
if (this->empty()) return T(0);
T res = back().distance(front());
for (int i = 0; i < this->size() - 1; ++i) res += at(i).distance(at(i + 1));
return res;
}
};
template <typename T>
Polygon<T> convexhull(const vector<Point<T>> &v) {
unsigned int N = (unsigned int)v.size();
vector<Point<T>> w(N + 1);
int lo = 0;
for (int i = 0; i < N; ++i)
if (v[i].second < v[lo].second) lo = i;
Point<T> o = v[lo];
for (int i = 0; i < N; ++i)
w[i + 1] = {v[i].first - o.first, v[i].second - o.second};
swap(w[1], w[lo + 1]);
sort(w.begin() + 2, w.end(), [](Point<T> &a, Point<T> &b) {
if (a.second == 0 && a.first > 0) return true;
if (b.second == 0 && b.first > 0) return false;
if (a.second > 0 && b.second < 0) return true;
return !(a.second < 0 && b.second > 0) &&
(a.first * b.second - a.second * b.first) > 1e-6;
});
w[0] = w[N];
unsigned int M = 1;
for (int i = 2; i <= N; ++i) {
while (ccw(w[M - 1], w[M], w[i]) <= 0)
if (M > 1)
--M;
else if (i == N)
break;
else
++i;
++M;
swap(w[M], w[i]);
}
Polygon<T> res(M);
for (int i = 0; i < M; ++i)
res[i] = {w[i + 1].first + o.first, w[i + 1].second + o.second};
return res;
}
class TaskA {
public:
void solve(istream &cin, ostream &cout) {
int N;
cin >> N;
double lo = 1e12;
double hi = 0;
Point<long long> P;
cin >> P;
vector<Point<long long>> R(N);
cin >> R;
for (int i = 0; i < N; ++i) {
double dist = R[i].distance(P);
lo = min(lo, dist);
hi = max(hi, dist);
}
for (int i = 0; i < N; ++i) {
auto a = R[i];
auto b = R[(i + 1) % N];
Segment<long long> S{a, b};
double dist = S.distance(P);
lo = min(lo, dist);
hi = max(hi, dist);
}
double ans = PI * (hi * hi - lo * lo);
cout << fixed << setprecision(10) << ans << endl;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
TaskA solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using std::string;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll my_exp(ll a, ll b) {
if (b == 0) {
return 1;
} else {
ll temp = my_exp(a, b / 2);
temp *= temp;
if (b % 2 == 1) {
temp *= a;
}
return temp;
}
}
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() {
double n, mini = 10000000, maxi = 0;
pair<double, double> p, a, first, b;
std::cin >> n >> p.first >> p.second;
std::cin >> a.first >> a.second;
mini = min(mini, sqrt(pow(double(p.first - a.first), 2) +
pow(double(p.second - a.second), 2)));
maxi = max(maxi, sqrt(pow(double(p.first - a.first), 2) +
pow(double(p.second - a.second), 2)));
first = a;
for (ll i = 1; i < n; i++) {
b = a;
std::cin >> a.first >> a.second;
mini = min(min(mini, sqrt(pow(double(p.first - a.first), 2) +
pow(double(p.second - a.second), 2))),
FindDistanceToSegment(a.first, a.second, b.first, b.second,
p.first, p.second));
maxi = max(maxi, sqrt(pow(double(p.first - a.first), 2) +
pow(double(p.second - a.second), 2)));
}
mini = min(mini, FindDistanceToSegment(a.first, a.second, first.first,
first.second, p.first, p.second));
std::cout
<< setprecision(20)
<< 3.141592653589793238462643383279502884197169399375105820974944592307816406286 *
(maxi * maxi - mini * mini)
<< std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <class T>
int getbit(int i, T X) {
return (X & (1 << (i - 1)));
}
template <class T>
T onbit(int i, T X) {
return (X | (1 << (i - 1)));
}
template <class T>
T offbit(int i, T X) {
return (X | (1 << (i - 1)) - (1 << (i - 1)));
}
template <class T>
T sqr(T x) {
return (x * x);
}
template <class T>
T cube(T x) {
return (x * x * x);
}
template <class T>
T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
int csx[4] = {0, 0, -1, 1};
int csy[4] = {-1, 1, 0, 0};
const int MOD = 1000000007;
const long long infi = 1e18;
const int maxn = 1e5;
const long double PI = 2 * acos(0.0);
int n;
pair<long double, long double> G, P[maxn + 5];
void enter() {
cin >> n;
cin >> G.first >> G.second;
for (int i = 1; i <= n; i++) cin >> P[i].first >> P[i].second;
}
long double distance(pair<long double, long double> A,
pair<long double, long double> B,
pair<long double, long double> C) {
long double ans = sqr((A.first - C.first) * (B.second - A.second) -
(B.first - A.first) * (A.second - C.second)) /
(sqr(B.second - A.second) + sqr(B.first - A.first));
return ans;
}
long double dis(pair<long double, long double> A,
pair<long double, long double> B) {
return (sqr(A.first - B.first) + sqr(A.second - B.second));
}
void solve() {
long double fmax = -1;
long double fmin = 1e18;
P[n + 1] = P[1];
for (int i = 1; i <= n; i++) {
fmax = max(fmax, dis(G, P[i]));
fmin = min(fmin, dis(P[i], G));
}
for (int i = 1; i <= n; i++) {
double z = dis(P[i + 1], P[i]);
double x = dis(G, P[i]);
double y = dis(G, P[i + 1]);
if (x + z < y) continue;
if (y + z < x) continue;
fmin = min(fmin, distance(P[i], P[i + 1], G));
}
long double ans = PI * (fmax - fmin);
cout << fixed;
cout << setprecision(18) << ans;
}
int main() {
enter();
solve();
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
using namespace std;
const int MAX = 1e5 + 5;
const long long MOD = 1000000007;
const long long MOD2 = 2010405347;
const long long INF = 9e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 315;
inline long long pw(long long x, long long y, long long md = MOD) {
long long ret = 1;
while (y) {
if (y & 1) ret = ret * x % md;
x = x * x % md, y >>= 1;
}
return ret;
}
inline void add(int &a, int b, int md = MOD) {
a = a + b >= md ? a + b - md : a + b;
}
int n;
array<long long, 2> p, x[MAX];
array<double, 2> c;
long long mx, z;
double mn, len, prj;
long long dot(array<long long, 2> a, array<long long, 2> b) {
return a[0] * b[0] + a[1] * b[1];
}
int main() {
cout << fixed << setprecision(10);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> p[0] >> p[1];
mn = INF;
for (int i = (1); i <= (n); ++i) {
cin >> x[i][0] >> x[i][1];
z = (x[i][0] - p[0]) * (x[i][0] - p[0]) +
(x[i][1] - p[1]) * (x[i][1] - p[1]);
mx = max(mx, z);
mn = min(mn, (double)z);
}
for (int i = (1); i <= (n); ++i) {
int j = i == 1 ? n : i - 1;
len = hypot(x[j][0] - x[i][0], x[j][1] - x[i][1]);
prj = dot({x[j][0] - x[i][0], x[j][1] - x[i][1]},
{p[0] - x[i][0], p[1] - x[i][1]}) /
len;
if (prj < 0.0 || prj > len) continue;
prj /= len;
c = {x[i][0] + (x[j][0] - x[i][0]) * prj,
x[i][1] + (x[j][1] - x[i][1]) * prj};
mn = min(mn, (p[0] - c[0]) * (p[0] - c[0]) + (p[1] - c[1]) * (p[1] - c[1]));
}
cout << (mx - mn) * pi << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<pair<long double, long double> > v;
pair<long double, long double> p;
int n;
bool valid(long double len) {
bool posi = false;
for (int i = 1; i <= n; i++) {
long double x1, x2, y1, y2;
y1 = v[i - 1].second - p.second;
y2 = v[i].second - p.second;
x1 = v[i - 1].first - p.first;
x2 = v[i].first - p.first;
long double p12, p22, p1p2;
long double a, b, c;
p12 = x1 * x1 + y1 * y1;
p22 = x2 * x2 + y2 * y2;
p1p2 = x1 * x2 + y1 * y2;
a = p12 + p22 - p1p2 * 2.0;
b = p1p2 * 2.0 - p12 * 2.0;
c = p12 - len * len;
if ((b * b - a * c * 4.0) < 0) continue;
long double det = b * b - a * c * 4.0;
det = sqrt(det);
long double alpha = (-b + det) / (a * 2.0);
long double beta = (-b - det) / (a * 2.0);
if (0 <= alpha && alpha <= 1) posi = true;
if (0 <= beta && beta <= 1) posi = true;
}
return posi;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> p.first >> p.second;
v.resize(n + 2);
long double mn, mx = -1;
int x, y;
for (int i = 0; i < n; i++) {
cin >> x >> y;
v[i].first = x;
v[i].second = y;
long double x1, x2, y1, y2;
y2 = v[i].second - p.second;
x2 = v[i].first - p.first;
mx = max(mx, sqrt(x2 * x2 + y2 * y2));
}
v[n] = v[0];
long double lo = 0.0, hi = mx;
long double mid;
long double ans = -1;
for (int i = 1; i <= 300; i++) {
mid = (lo + hi) / 2;
if (valid(mid) == true) {
ans = mid;
hi = mid;
} else
lo = mid;
}
mn = ans;
long double pi = acos(-1);
ans = pi * (mx * mx - mn * mn);
cout << setprecision(32) << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
long long int n, xx0, yy0;
long long int x[200010];
long long int y[200010];
long double pi = 3.1415926535897932384626433832795;
long double eps = 1e-15;
long long int dist(long long int ind) {
return (xx0 - x[ind]) * (xx0 - x[ind]) + (yy0 - y[ind]) * (yy0 - y[ind]);
}
long double sqr(long double a) { return (a * a); }
long double dist_p_p(long double ax, long double ay, long double bx,
long double by) {
return sqr(ax - bx) + sqr(ay - by);
}
long double dist_p_s(long double ox, long double oy, long double ax,
long double ay, long double bx, long double by) {
long double l, r, c, cx, cy, cz;
l = 0.0;
r = 1.0;
do {
c = (l + r) / 2.0;
cx = ax + (bx - ax) * c;
cy = ay + (by - ay) * c;
if ((ox - cx) * (bx - cx) + (oy - cy) * (by - cy) > 0)
l = c;
else
r = c;
} while (r - l > eps);
return dist_p_p(ox, oy, cx, cy);
}
int main() {
cin >> n;
cin >> xx0 >> yy0;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
}
int blz = 0;
for (int i = 0; i < n; i++) {
if (dist(i) < dist(blz)) blz = i;
}
int dal = 0;
for (int i = 0; i < n; i++) {
if (dist(i) > dist(dal)) dal = i;
}
long double distt = dist_p_s(xx0, yy0, x[0], y[0], x[1], y[1]);
for (int i = 0; i < n; i++) {
if (dist_p_s(xx0, yy0, x[i], y[i], x[(i + 1) % n], y[(i + 1) % n]) < distt)
distt = dist_p_s(xx0, yy0, x[i], y[i], x[(i + 1) % n], y[(i + 1) % n]);
}
long double r1 = pi * distt;
long double r2 = pi * dist(dal);
printf("%.15llf", r2 - r1);
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 10;
const double PI = acos(-1.0);
struct Point {
double a, b;
} p[MAX_N];
double getl(Point X, Point 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(Point A, Point B, Point 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() {
int n;
scanf("%d", &n);
Point T;
scanf("%lf%lf", &T.a, &T.b);
for (int i = 0; i < n; i++) scanf("%lf%lf", &p[i].a, &p[i].b);
double maxx = -(double)10000000;
double minn = (double)10000000;
double temp;
for (int i = 0; i < n; i++) {
minn = min(minn, getlength(p[i], p[(i + 1) % n], T, temp));
maxx = max(maxx, temp);
}
double ans = maxx * maxx - minn * minn;
ans *= PI;
printf("%.10lf\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, i;
double p[2], poly[100005][2], minD = 1e18, maxD = 0, d, answer, lo, hi,
EPS = 1e-12, mid1, mid2, x, y, d1, d2;
int main() {
scanf("%d %lf %lf", &n, &p[0], &p[1]);
for (i = 0; i < n; i++) {
scanf("%lf %lf", &poly[i][0], &poly[i][1]);
d = (poly[i][0] - p[0]) * (poly[i][0] - p[0]) +
(poly[i][1] - p[1]) * (poly[i][1] - p[1]);
maxD = max(maxD, d);
}
for (i = 0; i < n; i++) {
lo = 0;
hi = 1;
while (hi - lo > EPS) {
mid1 = lo + (hi - lo) / 3;
mid2 = mid1 + (hi - lo) / 3;
x = poly[i][0] + (poly[(i + 1) % n][0] - poly[i][0]) * mid1;
y = poly[i][1] + (poly[(i + 1) % n][1] - poly[i][1]) * mid1;
d1 = (x - p[0]) * (x - p[0]) + (y - p[1]) * (y - p[1]);
x = poly[i][0] + (poly[(i + 1) % n][0] - poly[i][0]) * mid2;
y = poly[i][1] + (poly[(i + 1) % n][1] - poly[i][1]) * mid2;
d2 = (x - p[0]) * (x - p[0]) + (y - p[1]) * (y - p[1]);
if (d1 < d2)
hi = mid2;
else
lo = mid1;
}
d = d1;
minD = min(minD, d);
}
answer = acos(-1.0) * (maxD - minD);
printf("%.18lf\n", answer);
return 0;
}
|
#include <bits/stdc++.h>
template <typename T>
using Vector2D = std::vector<std::vector<T>>;
template <typename T>
using Vector3D = std::vector<Vector2D<T>>;
using PairInt = std::pair<int, int>;
using PairInt64 = std::pair<int64_t, int64_t>;
using MapInt = std::map<int, int>;
using MMapInt = std::multimap<int, int>;
using MMapInt64 = std::multimap<int64_t, int64_t>;
using UMapIntString = std::unordered_map<int, std::string>;
using SetInt = std::set<int>;
using SetPairInt64 = std::set<PairInt64>;
using VectorInt = std::vector<int>;
using VectorInt2D = Vector2D<int>;
using VectorInt64 = std::vector<int64_t>;
using VectorUInt64 = std::vector<uint64_t>;
using VectorInt642D = Vector2D<int64_t>;
using VectorChar = std::vector<char>;
using VectorChar2D = Vector2D<char>;
using VectorString = std::vector<std::string>;
using QueuePairInt = std::queue<PairInt>;
using QueueInt = std::queue<int>;
using VectorPairInt = std::vector<PairInt>;
using VectorPairInt64 = std::vector<PairInt64>;
using VectorPairInt2D = Vector2D<PairInt>;
using SetInt = std::set<int>;
using MSetInt = std::multiset<int>;
using UMapChar = std::map<char, int>;
using ListInt = std::list<int>;
using VectorListInt = std::vector<ListInt>;
using VectorDouble = std::vector<double>;
double get_dist(int64_t x0, int64_t y0, int64_t x1, int64_t y1) {
int64_t dx = std::abs(x0 - x1);
int64_t dy = std::abs(y0 - y1);
return std::sqrt(static_cast<double>(dx) * dx + dy * dy);
}
double get_h(double a, double b, double c) {
double p = (a + b + c) / 2;
double s = (p * (p - a) * (p - b) * (p - c));
return 2.0 * std::sqrt(s) / a;
}
bool is_angle_gt_90(double a, double b, double c) {
return a * a > b * b + c * c;
}
int main() {
std::ios::sync_with_stdio(false);
int n;
int64_t x0;
int64_t y0;
std::cin >> n >> x0 >> y0;
int64_t x1;
int64_t y1;
std::cin >> x1 >> y1;
double dist_x1 = get_dist(x0, y0, x1, y1);
double dist_min = dist_x1;
double dist_max = dist_x1;
double dist_prev = dist_x1;
int64_t x_prev = x1;
int64_t y_prev = y1;
for (int i = 1; i < n; ++i) {
int64_t x;
int64_t y;
std::cin >> x >> y;
double dist = get_dist(x0, y0, x, y);
double dist_line = get_dist(x, y, x_prev, y_prev);
if (!is_angle_gt_90(dist, dist_prev, dist_line) &&
!is_angle_gt_90(dist_prev, dist, dist_line)) {
dist_min = std::min(dist_min, get_h(dist_line, dist, dist_prev));
}
dist_min = std::min(dist_min, dist);
dist_max = std::max(dist_max, dist);
dist_prev = dist;
x_prev = x;
y_prev = y;
}
double dist_line = get_dist(x1, y1, x_prev, y_prev);
if (!is_angle_gt_90(dist_x1, dist_prev, dist_line) &&
!is_angle_gt_90(dist_prev, dist_x1, dist_line)) {
dist_min = std::min(dist_min, get_h(dist_line, dist_x1, dist_prev));
}
double pi =
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821;
std::cout.precision(15);
double s = pi * dist_max * dist_max - pi * dist_min * dist_min;
std::cout << s;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long double const PI =
3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117;
long n;
cin >> n;
long double Px, Py;
cin >> Px >> Py;
long double closest_dist = 1000000000000000000, longest_dist = 0;
long double inputX, inputY, first_X, first_Y, lastX, lastY;
cin >> inputX >> inputY;
first_X = inputX;
first_Y = inputY;
lastX = inputX;
lastY = inputY;
long double dist =
(inputX - Px) * (inputX - Px) + (inputY - Py) * (inputY - Py);
closest_dist = min(closest_dist, dist);
longest_dist = max(longest_dist, dist);
for (long i = 0; i < n - 1; i++) {
cin >> inputX >> inputY;
dist = (inputX - Px) * (inputX - Px) + (inputY - Py) * (inputY - Py);
if (lastX != inputX and lastY != inputY) {
long double k = (lastY - inputY) / (long double)(lastX - inputX);
long double k2 = -1 / k;
long double U = (Py - (k2 * Px) - inputY + k * inputX) / (k - k2);
if ((lastX >= U and inputX <= U) or (lastX <= U and inputX >= U)) {
long double T = Py + k2 * (U - Px);
closest_dist =
min(closest_dist, ((Px - U) * (Px - U) + (Py - T) * (Py - T)));
}
} else {
if (lastX == inputX) {
if ((lastY >= Py and inputY <= Py) or (lastY <= Py and inputY >= Py)) {
closest_dist = min(closest_dist, (inputX - Px) * (inputX - Px));
}
} else {
if ((lastX >= Px and inputX <= Px) or (lastX <= Px and inputX >= Px)) {
closest_dist = min(closest_dist, (inputY - Py) * (inputY - Py));
}
}
}
lastX = inputX;
lastY = inputY;
closest_dist = min(closest_dist, dist);
longest_dist = max(longest_dist, dist);
}
inputX = first_X;
inputY = first_Y;
dist = (inputX - Px) * (inputX - Px) + (inputY - Py) * (inputY - Py);
if (lastX != inputX and lastY != inputY) {
long double k = (lastY - inputY) / (long double)(lastX - inputX);
long double k2 = -1 / k;
long double U = (Py - (k2 * Px) - inputY + k * inputX) / (k - k2);
if ((lastX >= U and inputX <= U) or (lastX <= U and inputX >= U)) {
long double T = Py + k2 * (U - Px);
closest_dist =
min(closest_dist, ((Px - U) * (Px - U) + (Py - T) * (Py - T)));
}
} else {
if (lastX == inputX) {
if ((lastY >= Py and inputY <= Py) or (lastY <= Py and inputY >= Py)) {
closest_dist = min(closest_dist, (inputX - Px) * (inputX - Px));
}
} else {
if ((lastX >= Px and inputX <= Px) or (lastX <= Px and inputX >= Px)) {
closest_dist = min(closest_dist, (inputY - Py) * (inputY - Py));
}
}
}
cout << setprecision(55) << PI * longest_dist - PI * closest_dist;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
double LenghtSq(double x, double y) { return (x * x + y * y); }
bool Tup(complex<double> A, complex<double> B, complex<double> C) {
return (((A - B).real() * (C - B).real()) +
((A - B).imag() * (C - B).imag())) < 0;
}
double Area(double a, double b, double c) {
double s = (a + b + c) / 2;
return sqrt(s * (s - a) * (s - b) * (s - c));
}
double Dist(complex<double> A, complex<double> B1, complex<double> B2) {
return 2 * Area(abs(A - B1), abs(A - B2), abs(B1 - B2)) / abs(B1 - B2);
}
int main() {
int n;
cin >> n;
double x, y;
cin >> x >> y;
vector<complex<double> > a(n);
for (int i = 0; i < n; i++) {
double c, d;
cin >> c >> d;
a[i] = complex<double>(c, d);
}
double Farest = 0;
for (double i = 0; i < n; i++) {
Farest = max(Farest, LenghtSq(x - a[i].real(), y - a[i].imag()));
}
double Closest = 10000000000;
for (int i = 0; i < n; i++) {
complex<double> A = a[i], B = a[(i + 1) % n], C = complex<double>(x, y);
if (Tup(A, B, C) || Tup(C, A, B)) {
Closest = min(Closest, min(abs(A - C), abs(B - C)));
} else
Closest = min(Closest, Dist(C, A, B));
}
cout << fixed;
cout << setprecision(6)
<< (Farest - Closest * Closest) * 3.1415926535897932384 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500100;
struct PP {
double x, y;
PP() {}
PP(long long xx, long long yy) {
x = xx;
y = yy;
}
void scan() { cin >> x >> y; }
PP operator-(PP b) { return PP(x - b.x, y - b.y); }
long long operator%(PP b) { return (x * b.y - y * b.x); }
long long operator*(PP b) { return (x * b.x + y * b.y); }
double len() { return x * x + y * y; }
double len(PP p) { return (*this - p).len(); }
} P;
long long px, py;
long long a, b, c;
void make_line(PP p, PP q) {
a = p.y - q.y;
b = q.x - p.x;
c = -(a * p.x + b * p.y);
}
bool f(PP p, PP q) {
PP v1 = P - p, v2 = q - p;
if (v1 * v2 < 0) return false;
v1 = P - q, v2 = p - q;
if (v1 * v2 < 0) return false;
return true;
}
int main() {
int n;
cin >> n;
P.scan();
PP p[n], M, m;
double r, R;
for (int i = 0; i < n; ++i) {
p[i].scan();
if (i == 0) {
R = p[i].len(P);
r = p[i].len(P);
}
r = min(r, p[i].len(P));
R = max(R, p[i].len(P));
if (i && f(p[i], p[i - 1])) {
make_line(p[i], p[i - 1]);
double D = (a * P.x + b * P.y + c);
D *= D;
D /= (double)(a * a + b * b);
r = min(r, D);
}
}
if (f(p[0], p[n - 1])) {
make_line(p[0], p[n - 1]);
double D = (a * P.x + b * P.y + c);
D *= D;
D /= (double)(a * a + b * b);
r = min(r, D);
}
printf("%.20lf\n", (R - r) * acos(-1.));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
double sq(double a) { return a * a; }
struct pos {
double y, x;
double sqdis(const pos& b) const { return sq(x - b.x) + sq(y - b.y); }
double dis(const pos& b) const { return sqrt(sqdis(b)); }
double cj(const pos& b) const { return x * b.y - y * b.x; }
};
pos p, ps[100000];
int main() {
int n;
double ty, tx, tmp, mx = 0, mi = 5e12;
double dis[3];
int i;
scanf("%d", &n);
scanf("%lf%lf", &p.x, &p.y);
for (i = 0; i < n; i++) {
scanf("%lf%lf", &tx, &ty);
ps[i].y = ty - p.y;
ps[i].x = tx - p.x;
}
for (i = 0; i < n; i++) {
tmp = sq(ps[i].y) + sq(ps[i].x);
if (tmp > mx) mx = tmp;
}
for (i = 0; i < n; i++) {
dis[0] = ps[i].sqdis(ps[(i + 1) % n]);
dis[1] = ps[i].sqdis((pos){0, 0});
dis[2] = ps[(i + 1) % n].sqdis((pos){0, 0});
if (dis[0] + dis[1] < dis[2] || dis[0] + dis[2] < dis[1])
tmp = min(dis[1], dis[2]);
else
tmp = sq(ps[i].cj(ps[(i + 1) % n]) / ps[i].dis(ps[(i + 1) % n]));
if (tmp < mi) mi = tmp;
}
printf("%.18lf\n", acos(-1) * (mx - mi));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int mod = 1e9 + 7;
struct Point {
double x, y;
} p[N];
double dist_P_P(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
double dist_P_L(Point a, Point b, Point c) {
double l1 = dist_P_P(a, b);
double l2 = dist_P_P(b, c);
double l3 = dist_P_P(c, a);
if (l2 * l2 >= l1 * l1 + l3 * l3) return l3;
if (l3 * l3 >= l1 * l1 + l2 * l2) return l2;
double A = a.y - b.y;
double B = b.x - a.x;
double C = a.x * b.y - a.y * b.x;
double D = A * c.x + B * c.y + C;
return fabs(D * D / (A * A + B * B));
}
int main() {
int n, i;
double nea = 1e18, far = 0;
scanf("%d", &n);
for (i = 0; i <= n; ++i) scanf("%lf%lf", &p[i].x, &p[i].y);
for (i = 1; i <= n; ++i) {
if (i < n)
nea = min(nea, dist_P_L(p[i], p[i + 1], p[0]));
else
nea = min(nea, dist_P_L(p[n], p[1], p[0]));
far = max(far, dist_P_P(p[0], p[i]));
}
printf("%.18lf\n", pi * (far - nea));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
double esp = 1e-11;
#pragma comment(linker, "/STACK:1024000000,1024000000")
const double PI = acos(-1.0);
const long long int INF = 0x3f3f3f3f3f3f3f3f;
const long long int MOD = 1000000007;
const int maxn = 100500;
struct point {
double x, y;
point() { x = y = 0; }
point(double x, double y) {
this->x = x;
this->y = y;
}
point operator*(const double &a) { return point(a * x, a * y); }
point operator/(const double &a) { return point(x / a, y / a); }
double operator*(const point &a) { return a.x * x + a.y * y; }
point operator+(const point &a) { return point(x + a.x, y + a.y); }
point operator-(const point &a) { return point(x - a.x, y - a.y); }
bool operator<(const point &a) const {
return x < a.x - esp || (abs(x - a.x) < esp && y < a.y - esp);
}
};
point operator*(double const &a, point const &b) {
return point(a * b.x, a * b.y);
}
double cross(point a, point b) { return a.x * b.y - a.y * b.x; }
double leng(point a) { return sqrt(a.x * a.x + a.y * a.y); }
vector<point> m;
double dmax = 0, dmin = INF * 1.0;
void f(double ans) {
dmax = max(dmax, ans);
dmin = min(dmin, ans);
}
int main() {
int n;
scanf("%d", &n);
int u, v;
m.clear();
scanf("%d%d", &u, &v);
point p(u, v);
point tem;
dmax = 0, dmin = INF;
double s1, s2, s3, coth;
for (int x = 1; x <= n; x++) {
scanf("%d%d", &u, &v);
tem.x = u;
tem.y = v;
m.push_back(tem);
f(leng(tem - p));
}
point a, b;
for (int x = 1; x < n; x++) {
a = m[x - 1];
b = m[x];
s1 = leng(b - a);
s2 = leng(p - b);
s3 = leng(p - a);
coth = s1 * s1 + s3 * s3 - s2 * s2;
coth /= (2.0 * s1 * s3);
if (s3 * coth > -esp && s3 * coth < s1 + esp) f(s3 * sqrt(1 - coth * coth));
}
a = m[0];
b = m[n - 1];
s1 = leng(b - a);
s2 = leng(p - b);
s3 = leng(p - a);
coth = s1 * s1 + s3 * s3 - s2 * s2;
coth /= (2.0 * s1 * s3);
if (s3 * coth > -esp && s3 * coth < s1 + esp) f(s3 * sqrt(1 - coth * coth));
double ans = PI * dmax * dmax;
ans -= PI * dmin * dmin;
printf("%.7f\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int M = 500010, mod = 1000000007;
const double PI = acos(-1.0);
class PT {
public:
double first, second;
PT() {}
PT(double first, double second) : first(first), second(second) {}
PT(const PT &p) : first(p.first), second(p.second) {}
double Magnitude() { return sqrt(first * first + second * second); }
PT operator+(const PT &p) const {
return PT(first + p.first, second + p.second);
}
PT operator-(const PT &p) const {
return PT(first - p.first, second - p.second);
}
PT operator*(double c) const { return PT(first * c, second * c); }
PT operator/(double c) const { return PT(first / c, second / c); }
};
double dot(PT p, PT q) { return p.first * q.first + p.second * q.second; }
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.first * q.second - p.second * q.first; }
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.first << "," << p.second << ")";
}
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.second, p.first); }
PT RotateCW90(PT p) { return PT(p.second, -p.first); }
PT RotateCCW(PT p, double t) {
return PT(p.first * cos(t) - p.second * sin(t),
p.first * sin(t) + p.second * 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 first, double second, double z, double a,
double b, double c, double d) {
return fabs(a * first + b * second + 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].second <= q.second && q.second < p[j].second ||
p[j].second <= q.second && q.second < p[i].second) &&
q.first < p[i].first + (p[j].first - p[i].first) *
(q.second - p[i].second) /
(p[j].second - p[i].second))
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;
}
vector<PT> CircleLineIntersection(PT a, PT b, PT c, double r) {
vector<PT> ret;
b = b - a;
a = a - c;
double A = dot(b, b);
double B = dot(a, b);
double C = dot(a, a) - r * r;
double D = B * B - A * C;
if (D < -1e-12) return ret;
ret.push_back(c + a + b * (-B + sqrt(D + 1e-12)) / A);
if (D > 1e-12) ret.push_back(c + a + b * (-B - sqrt(D)) / A);
return ret;
}
vector<PT> CircleCircleIntersection(PT a, PT b, double r, double R) {
vector<PT> ret;
double d = sqrt(dist2(a, b));
if (d > r + R || d + min(r, R) < max(r, R)) return ret;
double first = (d * d - R * R + r * r) / (2 * d);
double second = sqrt(r * r - first * first);
PT v = (b - a) / d;
ret.push_back(a + v * first + RotateCCW90(v) * second);
if (second > 0) ret.push_back(a + v * first - RotateCCW90(v) * second);
return ret;
}
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].first * p[j].second - p[j].first * p[i].second;
}
return area / 2.0;
}
double ComputeArea(const vector<PT> &p) { return fabs(ComputeSignedArea(p)); }
PT ComputeCentroid(const vector<PT> &p) {
PT c(0, 0);
double scale = 6.0 * ComputeSignedArea(p);
for (int i = 0; i < p.size(); i++) {
int j = (i + 1) % p.size();
c = c +
(p[i] + p[j]) * (p[i].first * p[j].second - p[j].first * p[i].second);
}
return c / scale;
}
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.first - b.first, a.second - b.second),
temp2(c.first - b.first, c.second - b.second);
double ans = asin((temp1.first * temp2.second - temp1.second * temp2.first) /
(temp1.Magnitude() * temp2.Magnitude()));
if ((ans < 0 &&
(temp1.first * temp2.first + temp1.second * temp2.second) < 0) ||
(ans >= 0 &&
(temp1.first * temp2.first + temp1.second * temp2.second) < 0))
ans = PI - ans;
ans = ans < 0 ? 2 * PI + ans : ans;
return ans;
}
double SignedArea(PT a, PT b, PT c) {
PT temp1(b.first - a.first, b.second - a.second),
temp2(c.first - a.first, c.second - a.second);
return 0.5 * (temp1.first * temp2.second - temp1.second * temp2.first);
}
bool XYasscending(PT a, PT b) {
if (abs(a.first - b.first) < 1e-12) return a.second < b.second;
return a.first < b.first;
}
void MakeConvexHull(vector<PT> given, vector<PT> &ans) {
int i, n = given.size(), j = 0, k = 0;
vector<PT> U, L;
ans.clear();
sort(given.begin(), given.end(), XYasscending);
for (i = 0; i < n; i++) {
while (true) {
if (j < 2) break;
if (SignedArea(L[j - 2], L[j - 1], given[i]) <= 0)
j--;
else
break;
}
if (j == L.size()) {
L.push_back(given[i]);
j++;
} else {
L[j] = given[i];
j++;
}
}
for (i = n - 1; i >= 0; i--) {
while (1) {
if (k < 2) break;
if (SignedArea(U[k - 2], U[k - 1], given[i]) <= 0)
k--;
else
break;
}
if (k == U.size()) {
U.push_back(given[i]);
k++;
} else {
U[k] = given[i];
k++;
}
}
for (i = 0; i < j - 1; i++) ans.push_back(L[i]);
for (i = 0; i < k - 1; i++) ans.push_back(U[i]);
}
vector<PT> p;
double maxdist(PT a, PT p, PT q) { return max(dist(a, p), dist(a, q)); }
double mindist(PT a, PT p, PT q) {
PT lt, rt;
int loop = 250;
while (loop--) {
lt.first = (p.first * 2.0 + q.first) / 3.0;
lt.second = (p.second * 2.0 + q.second) / 3.0;
rt.first = (p.first + q.first * 2.0) / 3.0;
rt.second = (p.second + q.second * 2.0) / 3.0;
if (dist(a, lt) < dist(a, rt))
q = rt;
else
p = lt;
}
return dist(a, p);
}
int main() {
ios_base::sync_with_stdio(false);
int n, i, j, k;
PT a, tmp;
cin >> n >> a.first >> a.second;
for (i = 0; i < n; i++) {
cin >> tmp.first >> tmp.second;
p.push_back(tmp);
}
double maxx = -10000000000000011;
for (i = 0; i < n; i++) {
j = (i + 1) % n;
maxx = max(maxx, maxdist(a, p[i], p[j]));
}
double minn = 10000000000000011;
for (i = 0; i < n; i++) {
j = (i + 1) % n;
minn = min(minn, mindist(a, p[i], p[j]));
}
cout << fixed << setprecision(10);
cout << PI * (maxx * maxx - minn * minn) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, px, py;
double dist(long long px, long long py, long long x1, long long y1,
long long x2, long long y2) {
double d2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
if (d2 == 0.0) return ((x1 - px) * (x1 - px) + (y1 - py) * (y1 - py));
double t = ((double)((px - x1) * (x2 - x1) + (py - y1) * (y2 - y1))) / d2;
if (t < 0.0)
return ((px - x1) * (px - x1) + (py - y1) * (py - y1));
else if (t > 1.0)
return ((px - x2) * (px - x2) + (py - y2) * (py - y2));
double nx = x1 + t * (x2 - x1);
double ny = y1 + t * (y2 - y1);
return ((nx - px) * (nx - px) + (ny - py) * (ny - py));
}
int main() {
const double PI = atan(1.0) * 4;
cin >> n >> px >> py;
vector<long long> d(n);
vector<double> d2(n);
vector<double> cs(0), xs(n), ys(n);
double x1, x2, y1, y2;
for (int i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
xs[i] = x;
ys[i] = y;
d[i] = (x - px) * (x - px) + (y - py) * (y - py);
}
for (int i = 0; i < n; i++) {
x1 = xs[i];
x2 = xs[(i + 1) % n];
y1 = ys[i];
y2 = ys[(i + 1) % n];
double dd = dist(px, py, x1, y1, x2, y2);
d2[i] = dd;
}
double maxd = max_element(d.begin(), d.end()) - d.begin();
double mind = min_element(d2.begin(), d2.end()) - d2.begin();
double res;
res = PI * (d[maxd] - d2[mind]);
cout.precision(20);
cout << res;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m;
double px, py;
vector<pair<double, double> > points;
double get_radius(int i) {
return (px - points[i].first) * (px - points[i].first) +
(py - points[i].second) * (py - points[i].second);
}
double get_dist(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
int main() {
scanf("%d %lf %lf", &n, &px, &py);
points.resize(n);
for (int i = 0; i < n; i++) {
scanf("%lf %lf", &points[i].first, &points[i].second);
}
double max_area = -100000000000000000;
double min_area = 100000000000000000;
for (int i = 0; i < n; i++) {
double radius = get_radius(i);
double area = 3.14159265358979323846 * radius;
max_area = max(max_area, area);
int j = (i + 1) % n;
double m1 = (points[j].second - points[i].second) /
(points[j].first - points[i].first);
double c1 = points[i].second - m1 * points[i].first;
double m2 = -1.0 / m1;
double c2 = py - px * m2;
double xp, yp;
if (points[i].first == points[j].first) {
xp = points[i].first;
yp = py;
} else if (points[i].second == points[j].second) {
xp = px;
yp = points[i].second;
} else {
xp = (c2 - c1) / (m1 - m2), yp = m2 * xp + c2;
}
if (get_dist(points[i].first, points[i].second, xp, yp) +
get_dist(points[j].first, points[j].second, xp, yp) -
get_dist(points[i].first, points[i].second, points[j].first,
points[j].second) <=
1e-9) {
double rad = (px - xp) * (px - xp) + (py - yp) * (py - yp);
min_area = min(min_area, 3.14159265358979323846 * rad);
} else {
double r1 = get_radius(i), r2 = get_radius(j);
min_area = min(min_area, 3.14159265358979323846 * min(r1, r2));
}
}
printf("%.20lf\n", max_area - min_area);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double inf = 1e20;
const double pi = acos(-1.0);
int sgn(double x) {
if (fabs(x) < eps) return 0;
if (x < 0)
return -1;
else
return 1;
}
double mysqrt(double x) { return sqrt(max(x, 0.0)); }
struct point {
double x, y;
point(double x = 0, double y = 0) : x(x), y(y) {}
bool operator==(const point &b) const {
return sgn(x - b.x) == 0 && sgn(y - b.x) == 0;
}
bool operator<(const point &b) const {
return sgn(x - b.x) == 0 ? sgn(y - b.y) < 0 : sgn(x - b.x) < 0;
}
point operator+(const point &b) const { return point(x + b.x, y + b.y); }
point operator-(const point &b) const { return point(x - b.x, y - b.y); }
point operator*(const double &k) const { return point(x * k, y * k); }
point operator/(const double &k) const { return point(x / k, y / k); }
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; }
double dist(point b) { return hypot(x - b.x, y - b.y); }
double rad(point a, point b) {
point p = *this;
return fabs(atan2(fabs((a - p) ^ (b - p)), (a - p) * (b - p)));
}
point trunc(double r) {
double l = hypot(x, y);
if (!sgn(l)) return *this;
r /= l;
return point(x * r, y * r);
}
point rotleft() { return point(-y, x); }
point rotright() { return point(y, -x); }
point rotate(point p, double angle) {
point v = (*this) - p;
double c = cos(angle), s = sin(angle);
return point(p.x + v.x * c - v.y * s, p.y + v.x * s + v.y * c);
}
void input() { scanf("%lf%lf", &x, &y); }
};
struct line {
point s, e;
line() {}
line(point s, point e) : s(s), e(e) {}
bool operator==(const line &v) { return (s == v.s) && (e == v.e); }
line(point p, double angle) {
s = p;
if (sgn(angle - pi / 2) == 0) {
e = (s + point(0, 1));
} else {
e = (s + point(1, tan(angle)));
}
}
line(double a, double b, double c) {
if (sgn(a) == 0) {
s = point(0, -c / b);
e = point(1, -c / b);
} else if (sgn(b) == 0) {
s = point(-c / a, 0);
e = point(-c / a, 1);
} else {
s = point(0, -c / b);
e = point(1, (-c - a) / b);
}
}
void adjust() {
if (e < s) swap(s, e);
}
double length() { return s.dist(e); }
double dispointtoline(point p) { return fabs((p - s) ^ (e - s)) / length(); }
double dispointtoseg(point p) {
if (sgn((p - s) * (e - s)) < 0 || sgn((p - e) * (s - e) < 0))
return min(p.dist(s), p.dist(e));
return dispointtoline(p);
}
};
const int N = 1e5 + 10;
point pp[N];
int main() {
int n;
point p;
scanf("%d", &n);
p.input();
double minn = inf, maxx = 0;
for (int i = 1; i <= n; i++) {
pp[i].input();
}
for (int i = 1; i <= n; i++) {
maxx = max(p.dist(pp[i]), maxx);
int j = i == n ? 1 : i + 1;
line line1 = line(pp[i], pp[j]);
minn = min(minn, line1.dispointtoseg(p));
}
printf("%lf\n", pi * (maxx * maxx - minn * minn));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
pair<double, double> center;
long long n;
inline double sqdist(pair<double, double> &a, pair<double, double> &b) {
return (a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second);
}
inline double dotProduct(pair<double, double> &a, pair<double, double> &b) {
return (center.first - a.first) * (b.first - a.first) +
(center.second - a.second) * (b.second - a.second);
}
inline double distFromLine(pair<double, double> &a, pair<double, double> &b) {
double c = a.first, d = a.second;
double e = b.first, first = b.second;
double x = center.first, y = center.second;
double denom = (first - d) * (first - d) + (c - e) * (c - e);
double num =
((first - d) * x + (c - e) * y - ((first - d) * c + (c - e) * d));
num = num * num;
return num / denom;
}
inline double nearest(vector<pair<double, double> > &points,
vector<double> &distances) {
double ans = 1e15;
long long i1, i2;
for (long long i = 0; i < n; ++i) {
i1 = i;
i2 = i + 1;
if (i2 == n) i2 = 0;
double dp = dotProduct(points[i1], points[i2]);
double len = sqdist(points[i1], points[i2]);
if (dp >= 0 && dp < len)
ans = min(ans, distFromLine(points[i1], points[i2]));
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> center.first >> center.second;
vector<pair<double, double> > points(n);
for (long long i = 0; i < n; i++) cin >> points[i].first >> points[i].second;
vector<double> distances(n);
for (long long i = 0; i < n; i++) distances[i] = sqdist(points[i], center);
double ri2, ro2;
ro2 = *max_element(distances.begin(), distances.end());
ri2 = *min_element(distances.begin(), distances.end());
ri2 = min(ri2, nearest(points, distances));
cout << fixed << setprecision(18);
;
cout << 3.141592653589793238 * (ro2 - ri2);
}
|
#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", &this->x, &this->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));
}
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 N = 2e5;
const long double Pi = 3.1415926535897932;
struct point {
int x, y;
} p, a[N];
int n;
long double mx, mn;
long double dist(point a, point b) {
long double ans;
ans = sqrt(1.0 * (a.x - b.x) * (a.x - b.x) + 1.0 * (a.y - b.y) * (a.y - b.y));
return ans;
}
struct node {
long double x, y;
} v[4];
long double F() {
long double ans = Pi * (mx * mx - mn * mn);
return ans;
}
long double len(node a) { return sqrt(1.0 * a.x * a.x + 1.0 * a.y * a.y); }
node do_it(point a, point b) {
node result;
result.x = b.x - a.x;
result.y = b.y - a.y;
return result;
}
long double dot(node a, node b) { return 1.0 * a.x * b.x + 1.0 * a.y * b.y; }
long double cross(node a, node b) { return 1.0 * a.x * b.y - 1.0 * b.x * a.y; }
long double dist_Point_line(point a, point b, point c) {
v[0] = do_it(a, b);
v[1] = do_it(a, c);
double area = fabs(cross(v[0], v[1]));
return area / (len(v[0]));
}
long double dist_Point_segment(point a, point b, point c) {
v[0] = do_it(a, b);
v[1] = do_it(a, c);
v[2] = do_it(b, a);
v[3] = do_it(b, c);
if (dot(v[0], v[1]) >= 0 && dot(v[2], v[3]) >= 0)
return dist_Point_line(a, b, c);
else
return min(len(v[1]), len(v[3]));
}
int main() {
scanf("%d%d%d", &n, &p.x, &p.y);
mn = 1e40;
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i].x, &a[i].y);
mx = max(mx, dist(a[i], p));
mn = min(mn, dist(a[i], p));
}
a[n + 1] = a[1];
for (int i = 1; i <= n; i++) {
int nxt = i + 1;
if (nxt > n) nxt = 1;
mx = max(mx, dist_Point_segment(a[i], a[nxt], p));
mn = min(mn, dist_Point_segment(a[i], a[nxt], p));
}
cout << fixed << setprecision(15) << F() << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
long double x, y;
cin >> x >> y;
long double maxi = 0, mini = 1e17;
long double prx = -1.5, pry = -1.5;
long double fx, fy;
for (int i = 0; i <= n; ++i) {
long double px, py;
if (i != n)
cin >> px >> py;
else
px = fx, py = fy;
if (i == 0) fx = px, fy = py;
maxi = max(maxi, abs(abs((px - x) * (px - x)) + abs((py - y) * (py - y))));
if (prx == -1.5) {
prx = px;
pry = py;
continue;
}
long double pr1 = prx, pr2 = pry;
long double diffX = px - prx;
long double diffY = py - pry;
long double x1 = prx, x2 = px, y1 = pry, y2 = py;
if ((diffX == 0) && (diffY == 0)) {
diffX = x - prx;
diffY = y - pry;
mini = min(diffX * diffX + diffY * diffY, mini);
prx = px;
pry = py;
continue;
}
long double t =
((x - x1) * diffX + (y - y1) * diffY) / (diffX * diffX + diffY * diffY);
if (t < 0) {
diffX = x - x1;
diffY = y - y1;
} else if (t > 1) {
diffX = x - x2;
diffY = y - y2;
} else {
diffX = x - (x1 + t * diffX);
diffY = y - (y1 + t * diffY);
}
mini = min(diffX * diffX + diffY * diffY, mini);
prx = px;
pry = py;
}
long double PI = acos(-1.0);
if (n == 1) {
cout << fixed << setprecision(10) << 0 << "\n";
} else {
long double fans = PI * (maxi - mini);
cout << fixed << setprecision(10) << fans << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long d(long long x1, long long y1, long long x2, long long y2) {
return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
}
long long x[110000], y[110000];
int n;
double t(int idx, long long x0, long long y0) {
return -(double)((y[(idx + 1) % n] - y[idx]) * (y[idx] - y0) +
(x[(idx + 1) % n] - x[idx]) * (x[idx] - x0)) /
(double)d(x[(idx + 1) % n], y[(idx + 1) % n], x[idx], y[idx]);
}
bool lies(int idx, long long x0, long long y0) {
if (-((y[(idx + 1) % n] - y[idx]) * (y[idx] - y0) +
(x[(idx + 1) % n] - x[idx]) * (x[idx] - x0)) >= 0 &&
-((y[(idx + 1) % n] - y[idx]) * (y[idx] - y0) +
(x[(idx + 1) % n] - x[idx]) * (x[idx] - x0)) <=
d(x[(idx + 1) % n], y[(idx + 1) % n], x[idx], y[idx]))
return true;
else
return false;
}
int main() {
long long x0, y0, dist_max = 0ll;
double dist_min = INFINITY;
scanf("%d %lld %lld", &n, &x0, &y0);
for (int i = 0; i < n; i++) {
scanf("%lld %lld", &x[i], &y[i]);
dist_max = max(dist_max, d(x[i], y[i], x0, y0));
}
for (int i = 0; i < n; i++) {
if (lies(i, x0, y0)) {
double m_t = t(i, x0, y0);
double dist1 = (double)x[i] + m_t * (double)(x[(i + 1) % n] - x[i]) - x0;
dist1 *= dist1;
double dist2 = (double)y[i] + m_t * (double)(y[(i + 1) % n] - y[i]) - y0;
dist2 *= dist2;
dist_min = min(dist_min, dist1 + dist2);
} else {
dist_min = min(dist_min, (double)d(x[i], y[i], x0, y0));
dist_min =
min(dist_min, (double)d(x[(i + 1) % n], y[(i + 1) % n], x0, y0));
}
}
double solution = (double)dist_max * M_PI;
solution -= dist_min * M_PI;
printf("%.15f\n", solution);
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
inline void readchar(char &ch) {
while ((ch = getchar()) == ' ' || ch == '\n')
;
}
inline void read(int &x) {
char ch;
while ((ch = getchar()) < '0' || ch > '9')
;
x = ch - '0';
while ((ch = getchar()) <= '9' && ch >= '0') x = x * 10 + ch - '0';
}
long long x[maxn], y[maxn];
int n, px, py, cnt;
double R, r;
template <class T>
double sqr(T x) {
return (double)x * x;
}
int main() {
scanf("%d%d%d", &n, &px, &py);
for (int i = 1; i <= n; i++)
scanf("%I64d%I64d", &(x[i]), &(y[i])), (x[i]) -= px, (y[i]) -= py;
x[n + 1] = x[1];
y[n + 1] = y[1];
for (int i = 1; i <= n; i++) R = max(R, sqr((x[i])) + sqr((y[i])));
r = 1e100;
for (int i = 1; i <= n; i++) {
if ((x[i]) == 0 && (x[i + 1]) == 0) {
if ((y[i]) * (y[i + 1]) <= 0)
r = 0;
else
r = min(r, min(fabs((y[i])), fabs((y[i + 1]))));
continue;
}
double x0 = (double)((x[i + 1]) * (y[i]) - (x[i]) * (y[i + 1])) *
((y[i]) - (y[i + 1])) /
(double)(((x[i]) - (x[i + 1])) * ((x[i]) - (x[i + 1])) +
((y[i]) - (y[i + 1])) * ((y[i]) - (y[i + 1])));
if (x0 >= (x[i]) && x0 <= (x[i + 1]) || x0 >= (x[i + 1]) && x0 <= (x[i]))
r = min(r, sqr((x[i + 1]) * (y[i]) - (x[i]) * y[i + 1]) /
(sqr((x[i]) - (x[i + 1])) + sqr((y[i]) - (y[i + 1]))));
else
r = min(
r, min(sqr((x[i])) + sqr((y[i])), sqr((x[i + 1])) + sqr((y[i + 1]))));
}
printf("%lf\n", 4 * atan(1) * (R - r));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001000;
const double eps = 1e-10, inf = 1e20, pi = acos(-1);
struct poi {
double x, y;
} c, p[maxn];
poi operator-(const poi &a, const poi &b) {
return (poi){a.x - b.x, a.y - b.y};
}
int dcmp(double x) { return fabs(x) < eps ? 0 : x < 0 ? -1 : 1; }
double dot(poi a, poi b) { return a.x * b.x + a.y * b.y; }
double cross(poi a, poi b) { return a.x * b.y - a.y * b.x; }
int n;
double mxd = -1, mnd = inf;
double poi_dis_to_seg(poi p, poi a, poi b) {
poi AB = b - a, AP = p - a, BP = p - b;
if (dcmp(dot(AB, AP)) < 0) return dot(AP, AP);
if (dcmp(dot(AB, BP)) > 0) return dot(BP, BP);
return pow(fabs(cross(AB, AP) / sqrt(dot(AB, AB))), 2);
}
int main() {
scanf("%d%lf%lf", &n, &c.x, &c.y);
for (int i = 1; i <= n; i++) scanf("%lf%lf", &p[i].x, &p[i].y);
for (int i = 1; i <= n; i++) {
mxd = max(mxd, dot(p[i] - c, p[i] - c));
double dis = poi_dis_to_seg(c, p[i % n + 1], p[i]);
mnd = min(mnd, dis);
}
printf("%.12lf\n", pi * (mxd - mnd));
return 0;
}
|
#include <bits/stdc++.h>
long double pi = acos(-1.0);
using namespace std;
long double dist(long long x1, long long y1, long long x2, long long y2) {
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}
long double dist2(long long x, long long y, pair<long long, long long> p1,
pair<long long, long long> p2) {
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long long x, y;
cin >> x >> y;
long double mn = 1e18, mx = -1e18;
vector<pair<long long, long long>> xy;
for (long long(i) = 0; (i) < n; (i)++) {
long long xx, yy;
cin >> xx >> yy;
xx -= x;
yy -= y;
mx = max(mx, dist(0, 0, xx, yy));
xy.push_back({xx, yy});
}
x = 0, y = 0;
for (long long(i) = 0; (i) < n; (i)++) {
pair<long long, long long> p1 = xy[i];
pair<long long, long long> p2 = xy[(i + 1) % n];
long double a = dist(p1.first, p1.second, p2.first, p2.second);
long double b = dist(x, y, p1.first, p1.second);
long double c = dist(x, y, p2.first, p2.second);
pair<long long, long long> v1 =
make_pair(p1.first - p2.first, p1.second - p2.second);
pair<long long, long long> v2 = make_pair(p2.first, p2.second);
pair<long long, long long> v3 = make_pair(p1.first, p1.second);
long double alpha1 =
acos((v2.first * v1.first + v2.second * v1.second) / (c * a));
v1.first *= -1;
v1.second *= -1;
long double alpha2 =
acos((v3.first * v1.first + v3.second * v1.second) / (b * a));
int q1 = 1, q2 = 1;
if (alpha1 > pi / 2.0) {
q1 = -1;
}
if (alpha2 > pi / 2.0) {
q2 = -1;
}
bool ok1 = q1 * q2 > 0;
mn = min({mn, b, c});
if (ok1) {
if (b > c) swap(b, c);
long double pp = (a + b + c) / 2.0;
long double s = sqrt(pp * (pp - a) * (pp - b) * (pp - c));
long double h = 2 * s / a;
mn = min(mn, h);
}
}
cout << setprecision(20) << fixed << pi * (mx * mx - mn * mn);
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.