text
stringlengths
49
983k
#include <bits/stdc++.h> char _; using namespace std; int N, C, D; pair<int, int> A[400000]; long long Z, ZO, ZOZ, O, OZ, OZO; inline bool cmp(const pair<int, int>& a, const pair<int, int>& b) { if ((b.second < 0) ^ (a.second < 0)) return 1LL * a.first * b.second > 1LL * b.first * a.second; return 1LL * a.first * b.second < 1LL * b.first * a.second; } inline bool eq(const pair<int, int>& a, const pair<int, int>& b) { return 1LL * a.first * b.second == 1LL * b.first * a.second; } int main() { do { while ((N = getchar()) < '0') ; for (N -= '0'; '0' <= (_ = getchar()); N = (N << 3) + (N << 1) + _ - '0') ; } while (0); do { while ((C = getchar()) < '0') ; for (C -= '0'; '0' <= (_ = getchar()); C = (C << 3) + (C << 1) + _ - '0') ; } while (0); do { while ((D = getchar()) < '0') ; for (D -= '0'; '0' <= (_ = getchar()); D = (D << 3) + (D << 1) + _ - '0') ; } while (0); for (int i = 0; i < N; i++) { do { while ((A[i].first = getchar()) < '0') ; for (A[i].first -= '0'; '0' <= (_ = getchar()); A[i].first = (A[i].first << 3) + (A[i].first << 1) + _ - '0') ; } while (0); do { while ((A[i].second = getchar()) < '0') ; for (A[i].second -= '0'; '0' <= (_ = getchar()); A[i].second = (A[i].second << 3) + (A[i].second << 1) + _ - '0') ; } while (0); A[i].first -= C, A[i].second -= D; } sort(A, A + N, cmp); for (int i = 0, j; i < N; i = j) { long long NZ = Z, NZO = ZO, NZOZ = ZOZ, NO = O, NOZ = OZ, NOZO = OZO; for (j = i; j < N && eq(A[i], A[j]); j++) { if (A[j].second < 0) { NOZO += OZ; NZO += Z; NO++; } else { NZOZ += ZO; NOZ += O; NZ++; } } Z = NZ, ZO = NZO, ZOZ = NZOZ, O = NO, OZ = NOZ, OZO = NOZO; } int L = 0, R = 0, D = 0; for (int i = 0; i < N; i++) if (A[i].second == 0) { if (A[i].first < 0) L++; else R++; } for (int i = 0; i < N; i++) if (A[i].second < 0) D++; printf("%lld\n", OZO + ZOZ - 1LL * L * R * D); return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; long long powmod(long long a, long long b) { long long res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } inline int getint() { int ret = 0, ch; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) ; for (ret = ch - '0', ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar()) { ret = ret * 10 + ch - '0'; } return ret; } bool my_comp(const pair<pair<long long, long long>, int>& l, const pair<pair<long long, long long>, int>& r) { if (l.first.first * r.first.second == l.first.second * r.first.first) return l.second < r.second; return l.first.first * r.first.second < l.first.second * r.first.first; } int n, a, b, c, d; vector<pair<pair<long long, long long>, int> > g; int prevIdx[345700], nextIdx[345700]; long long cnt[345700][2], revcnt[345700][2]; int main() { n = getint(); c = getint(); d = getint(); for (int i = 0; i < (int)n; i++) { a = getint(); b = getint(); a -= c; b -= d; if (a >= 0 && b >= 0) g.push_back(make_pair(make_pair(a, b), 0)); else if (a < 0 && b < 0) g.push_back(make_pair(make_pair(-a, -b), 1)); else if (a >= 0) g.push_back(make_pair(make_pair(a, -b), 2)); else g.push_back(make_pair(make_pair(-a, b), 3)); } sort(g.begin(), g.end(), &my_comp); long long prevX = g[0].first.first, prevY = g[0].first.second, idx = 0; int p = -1; for (int i = 0; i < (int)n; i++) { long long X = g[i].first.first, Y = g[i].first.second; int P = g[i].second; if (X * Y == 0) { prevIdx[i] = i; } else { if (X * prevY == Y * prevX && p / 2 == P / 2) { prevIdx[i] = idx; } else { prevIdx[i] = i; prevX = X; prevY = Y; idx = i; p = P; } } } prevX = g[n - 1].first.first, prevY = g[n - 1].first.second, idx = n + 1, p = -1; for (int i = n - 1; i >= 0; i--) { long long X = g[i].first.first, Y = g[i].first.second; int P = g[i].second; if (X * Y == 0) { nextIdx[i] = i + 2; } else { if (X * prevY == Y * prevX && p / 2 == P / 2) { nextIdx[i] = idx; } else { nextIdx[i] = i + 2; prevX = X; prevY = Y; idx = i + 2; p = P; } } } for (int i = 0; i < (int)g.size(); i++) { int p = g[i].second; long long q = g[i].first.second; if (q > 0) { if (p == 0 || p == 3) cnt[i + 1][0] = cnt[i][0] + 1, cnt[i + 1][1] = cnt[i][1]; else cnt[i + 1][0] = cnt[i][0], cnt[i + 1][1] = cnt[i][1] + 1; } else cnt[i + 1][0] = cnt[i][0], cnt[i + 1][1] = cnt[i][1]; } for (int i = g.size() - 1; i >= 0; i--) { int p = g[i].second; long long q = g[i].first.first; if (q > 0) { if (p == 0 || p == 2) revcnt[i + 1][0] = revcnt[i + 2][0] + 1, revcnt[i + 1][1] = revcnt[i + 2][1]; else revcnt[i + 1][0] = revcnt[i + 2][0], revcnt[i + 1][1] = revcnt[i + 2][1] + 1; } else revcnt[i + 1][0] = revcnt[i + 2][0], revcnt[i + 1][1] = revcnt[i + 2][1]; } long long ans = 0; for (int i = 0; i < (int)g.size(); i++) { int p = g[i].second; if (g[i].first.first * g[i].first.second == 0) continue; long long c1 = cnt[prevIdx[i]][0], c2 = cnt[prevIdx[i]][1], rc1 = revcnt[nextIdx[i]][0], rc2 = revcnt[nextIdx[i]][1]; if (p == 0) ans += c2 * rc2; else if (p == 1) ans += c1 * rc1; else if (p == 2) ans += c1 * rc2; else if (p == 3) ans += c2 * rc1; } printf("%I64d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; struct point { int x, y; point() {} point(int _x, int _y) : x(_x), y(_y) {} point operator-(const point& other) const { return point(other.x - x, other.y - y); } long long operator/(const point& other) const { return x * 1LL * other.y - y * 1LL * other.x; } bool operator<(const point& other) const { if (x == other.x) return y < other.y; return x < other.x; } bool operator==(const point& other) const { return x == other.x && y == other.y; } bool operator!=(const point& other) const { return !(*this == other); } }; int gcd(int a, int b) { while (b != 0) { int r = a % b; a = b; b = r; } return a; } const int maxn = 4e5 + 5; int n, c, d; map<point, int> mp; vector<point> p; long long pref[maxn]; void read_input() { cin >> n >> c >> d; for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; x -= c; y -= d; int t = gcd(abs(x), abs(y)); x /= t; y /= t; if (mp.count(point(x, y)) == 0) p.push_back(point(x, y)); ++mp[point(x, y)]; } } int up(point u) { if (u.y == 0) return u.x > 0; return u.y > 0; } bool cmp(const point& u, const point& v) { int up_u = up(u), up_v = up(v); if (up_u == up_v) return u / v > 0; return up_u > up_v; } void init() { sort(p.begin(), p.end(), cmp); pref[0] = 0; for (int i = 0; i < (int)p.size(); ++i) pref[i + 1] = pref[i] + mp[p[i]]; } point modify(point u) { return point(-u.x, -u.y); } void solve() { long long ans = 0; long long total_cnt = 0; long long total = 0; for (int cur = 0, nxt = 0; cur < (int)p.size(); ++cur) { int t = lower_bound(p.begin(), p.end(), modify(p[cur]), cmp) - p.begin(); if (up(p[cur])) t = 0; total -= mp[p[cur]] * 1LL * pref[t]; total_cnt -= mp[p[cur]]; while (nxt < (int)p.size() && p[cur] / p[nxt] >= 0 && modify(p[cur]) != p[nxt]) { t = lower_bound(p.begin(), p.end(), modify(p[nxt]), cmp) - p.begin(); if (up(p[nxt])) t = 0; total += mp[p[nxt]] * 1LL * pref[t]; total_cnt += mp[p[nxt]]; ++nxt; } t = upper_bound(p.begin(), p.end(), modify(p[cur]), cmp) - p.begin(); if (up(p[cur])) t = 0; ans += mp[p[cur]] * 1LL * total; ans -= mp[p[cur]] * 1LL * pref[t] * total_cnt; } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read_input(); init(); solve(); }
#include <bits/stdc++.h> using namespace std; using lli = long long int; using llu = long long unsigned; using pii = tuple<lli, lli>; using ppii = tuple<pii, pii>; using piii = tuple<lli, lli, lli>; using vi = vector<lli>; using vii = vector<pii>; using viii = vector<piii>; using vvi = vector<vi>; using vvii = vector<vii>; using vviii = vector<viii>; using vvvii = vector<vvii>; using pt = complex<lli>; template <class A, class B> ostream& operator<<(ostream& s, pair<A, B> const& a) { return s << "(" << get<0>(a) << "," << get<1>(a) << ")"; } template <class A, class B> ostream& operator<<(ostream& s, tuple<A, B> const& a) { return s << "(" << get<0>(a) << "," << get<1>(a) << ")"; } template <class A, class B, class C> ostream& operator<<(ostream& s, tuple<A, B, C> const& a) { return s << "(" << get<0>(a) << "," << get<1>(a) << "," << get<2>(a) << ")"; } template <class T> ostream& operator<<(ostream& s, vector<T> const& a) { for (lli i = 0; i < (lli)(a.size()); ++i) { s << a[i]; if (i != (lli)a.size() - 1) s << " "; } return s; } lli gcd(lli a, lli b) { return (a % b == 0) ? b : gcd(b, a % b); } pii no(pii const& a) { pii b = a; auto g = gcd(get<0>(b), get<1>(b)); get<0>(b) /= g; get<1>(b) /= g; if (get<1>(b) < 0) { get<0>(b) *= -1; get<1>(b) *= -1; } return b; } struct cmp { bool operator()(pii const& a, pii const& b) const { return get<0>(a) * get<1>(b) > get<0>(b) * get<1>(a); } }; int main(int, char**) { ios::sync_with_stdio(false); lli n, c, d; cin >> n >> c >> d; map<pii, array<int, 2>, cmp> A; lli B[2] = {0, 0}; for (lli i = 0; i < (lli)(n); ++i) { lli r, w; cin >> r >> w; r -= c; w -= d; if (w != 0) { auto a_ = no(make_tuple(r, w)); A[a_][w > 0] += 1; } else B[r > 0] += 1; } lli R[2] = {0, 0}; lli L[2] = {0, 0}; lli r = 0; for (auto x : A) for (lli i = 0; i < (lli)(2); ++i) R[i] += x.second[i]; for (auto x : A) { for (lli i = 0; i < (lli)(2); ++i) R[i] -= x.second[i]; for (lli i = 0; i < (lli)(2); ++i) r += x.second[i] * L[1 - i] * R[1 - i]; for (lli i = 0; i < (lli)(2); ++i) r += x.second[i] * B[i] * L[1 - i]; for (lli i = 0; i < (lli)(2); ++i) L[i] += x.second[i]; } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 350000; struct P { int x, y; P() {} P(int _x, int _y) { x = _x; y = _y; } bool be() const { return x ? x > 0 : y > 0; } P operator+(const P &a) const { return P(x + a.x, y + a.y); } P operator-(const P &a) const { return P(x - a.x, y - a.y); } long long operator*(const P &a) const { return 1ll * x * a.y - 1ll * y * a.x; } bool operator==(const P &a) const { return 1ll * x * a.y == 1ll * y * a.x && be() == a.be(); } } p[N * 2]; long long ans, SSS[N * 2]; int n, PX, PY; int S[N * 2], SS[N * 2]; bool cmp(P x, P y) { return x.be() ^ y.be() ? x.be() : x * y > 0; } int main() { scanf("%d%d%d", &n, &PX, &PY); for (int i = (int)(1); i <= (int)(n); i++) { scanf("%d%d", &p[i].x, &p[i].y); p[i].x -= PX; p[i].y -= PY; } sort(p + 1, p + n + 1, cmp); int top = 1; S[1] = 1; for (int i = (int)(2); i <= (int)(n); i++) { if (!(p[i] == p[i - 1])) p[++top] = p[i]; ++S[top]; } n = top; for (int i = (int)(1); i <= (int)(n); i++) { p[i + n] = p[i]; S[i + n] = S[i]; } for (int i = (int)(1); i <= (int)(n * 2); i++) { SS[i] = SS[i - 1] + S[i]; SSS[i] = SSS[i - 1] + 1ll * S[i] * S[i]; } for (int i = (int)(1); i <= (int)(n); i++) ans += 1ll * S[i] * (1ll * SS[i - 1] * SS[i - 1] - SSS[i - 1]) / 2; int p1 = 1; for (int i = (int)(1); i <= (int)(n); i++) { p1 = max(p1, i); for (; p1 + 1 != i + n && p[i] * p[p1 + 1] >= 0; ++p1) ; ans -= 1ll * S[i] * (1ll * (SS[p1] - SS[i]) * (SS[p1] - SS[i]) - (SSS[p1] - SSS[i])) / 2; } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; struct node { double x; int flag; } q[350000]; bool cmp(node a, node b) { return a.x > b.x; } int cnt; long long cntzero1, cntzero2; int r[350000], w[350000]; int fir[350000], las[350000]; long long fsum1[350000], fsum2[350000], lsum1[350000], lsum2[350000], ans; int main() { int n, c, d; scanf("%d%d%d", &n, &c, &d); for (int i = 1; i <= n; i++) { scanf("%d%d", &r[i], &w[i]); r[i] -= c, w[i] -= d; if (w[i] == 0) { r[i] > 0 ? cntzero1++ : cntzero2++; } else { q[++cnt].x = r[i] * 1.0 / w[i]; w[i] > 0 ? q[cnt].flag = 1 : q[cnt].flag = -1; } } sort(q + 1, q + cnt + 1, cmp); int j; for (int i = 1; i <= cnt; i = j + 1) { j = i; while (j + 1 <= cnt && q[j + 1].x == q[i].x) j++; for (int k = i; k <= j; k++) { fir[k] = i, las[k] = j; } } for (int i = 1; i <= cnt; i++) { fsum1[i] = fsum1[i - 1], fsum2[i] = fsum2[i - 1]; q[i].flag > 0 ? fsum1[i]++ : fsum2[i]++; } for (int i = cnt; i >= 1; i--) { lsum1[i] = lsum1[i + 1], lsum2[i] = lsum2[i + 1]; q[i].flag > 0 ? lsum1[i]++ : lsum2[i]++; } for (int i = 1; i <= cnt; i++) { (q[i].flag > 0) ? ans += fsum2[fir[i] - 1] * lsum2[las[i] + 1] : ans += fsum1[fir[i] - 1] * lsum1[las[i] + 1]; } long long num1 = 0, num2 = 0; for (int i = 1; i <= cnt; i++) { if (q[i].flag > 0) num1 += fsum2[fir[i] - 1]; else num2 += fsum1[fir[i] - 1]; } ans += cntzero1 * num1 + cntzero2 * num2; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long double ang[1000000]; long long s[1000000], g[1000000]; int main() { const long double pi = atan2((long double)(0.0), (long double)(-1.0)); const long double eps = 1e-18; long long c, d, x, y; long long i, j, k, n, m, ans = 0; cin >> n >> c >> d; for (i = 1; i <= n; i++) { scanf("%I64d%I64d", &x, &y); ang[i] = (long double)atan2((long double)(y - d), (long double)(x - c)); if (ang[i] < 0) ang[i] += (long double)(2.0) * pi; } sort(ang + 1, ang + 1 + n); for (i = 1; i <= n; i++) ang[n + i] = ang[i] + (long double)(2.0) * pi; j = 0; for (i = 1; i <= n; i++) { while (ang[j + 1] - ang[i] < pi - eps) j++; s[i] = j; } for (i = 1; i <= n; i++) s[i + n] = s[i] + n; for (i = 2; i <= n * 2; i++) s[i] += s[i - 1]; j = 0; for (i = 1; i <= n; i++) { while (ang[j + 1] - ang[i] < pi + eps) j++; g[i] = j; } long long l = 1, r = 0; for (i = 1; i <= n; i++) { while (ang[l] - ang[i] < eps) l++; while (ang[r + 1] - ang[i] < pi - eps) r++; if (ang[l] - ang[i] > eps) ans += (s[r] - s[l - 1]) - g[i] * (r - l + 1); } cout << ans / 3; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 400005; struct frac { int x, y; frac(int _x, int _y) { x = _x; y = _y; if (y < 0) { x = -x; y = -y; } } frac() {} bool operator<(const frac &rhs) const { return (long long)x * rhs.y < (long long)rhs.x * y; } }; int N; int C, D; int r[MAXN], w[MAXN]; vector<frac> V[3]; long long cnt[2]; void load() { scanf("%d%d%d", &N, &C, &D); for (int i = 0; i < N; i++) scanf("%d%d", r + i, w + i); } int sgn(int x) { return x ? x > 0 : 2; } long long get(int idx, frac val) { pair<vector<frac>::iterator, vector<frac>::iterator> tmp = equal_range(V[idx].begin(), V[idx].end(), val); cnt[idx ^ 1] += (long long)(V[idx].end() - tmp.second); return (long long)(tmp.first - V[idx].begin()) * (V[idx].end() - tmp.second); } long long solve() { for (int i = 0; i < N; i++) { r[i] -= C; w[i] -= D; V[sgn(w[i])].push_back(frac(r[i], w[i])); } for (int i = 0; i < 2; i++) sort(V[i].begin(), V[i].end()); long long sol = 0; for (int k = 0; k < 2; k++) for (int i = 0; i < V[k].size(); i++) sol += get(k ^ 1, V[k][i]); for (int i = 0; i < V[2].size(); i++) sol += cnt[sgn(V[2][i].x)]; return sol; } int main() { load(); printf("%I64d\n", solve()); return 0; }
#include <bits/stdc++.h> using namespace std; long double ang[1000000]; long long s[1000000], g[1000000]; int main() { long double pi = atan2((long double)(0.0), (long double)(-1.0)); long double eps = 1e-18; long long c, d, x, y; long long i, j, k, n, m, ans = 0; cin >> n >> c >> d; for (i = 1; i <= n; i++) { scanf("%I64d%I64d", &x, &y); ang[i] = (long double)atan2((long double)(y - d), (long double)(x - c)); if (ang[i] < 0) ang[i] += (long double)(2.0) * pi; } sort(ang + 1, ang + 1 + n); for (i = 1; i <= n; i++) ang[n + i] = ang[i] + (long double)(2.0) * pi; j = 0; for (i = 1; i <= n; i++) { while (ang[j + 1] - ang[i] < pi - eps) j++; s[i] = j; } for (i = 1; i <= n; i++) s[i + n] = s[i] + n; for (i = 2; i <= n * 2; i++) s[i] += s[i - 1]; j = 0; for (i = 1; i <= n; i++) { while (ang[j + 1] - ang[i] < pi + eps) j++; g[i] = j; } long long l = 1, r = 0; for (i = 1; i <= n; i++) { while (ang[l] - ang[i] < eps) l++; while (ang[r + 1] - ang[i] < pi - eps) r++; if (ang[l] - ang[i] > eps) ans += (s[r] - s[l - 1]) - g[i] * (r - l + 1); } cout << ans / 3; }
#include <bits/stdc++.h> struct point { int x, y; }; inline bool cmp(const point &a, const point &b) { bool aflg = a.x <= 0, bflg = b.x <= 0; if (aflg ^ bflg) return aflg < bflg; if (!a.x) { if (a.y > 0) return true; return false; } if (!b.x) { if (b.y > 0) return false; return true; } return (long long)a.y * b.x < (long long)a.x * b.y; } char ibuf[7605000], *ip = ibuf; inline void readi(int &n) { while (*ip < 49 || *ip > 57) ip++; n = *ip++ - 48; while (48 <= *ip && *ip <= 57) n = (n << 1) + (n << 3) + *ip++ - 48; } inline void readp(const int &n, const int c, const int d, point *p) { int x, y, i = 0; while (i < n) { readi(x); readi(y); x -= c; y -= d; p[i++] = (point){x, y}; } std::sort(p, p + n, cmp); } point p[345679]; int s[345678], stp[345678], us[345678]; int main() { fread(ibuf, 7605000, 1, stdin); int c, d; readi(c); const int n = c; readi(c); readi(d); readp(n, c, d, p); d = 0; while (d < n && p[d].x > 0) d++; if (d == n) { putchar(48); return 0; } int nm; const int nd = d; for (c = 0; c < n; c++) { while (d < n && (long long)p[c].x * p[d].y - (long long)p[d].x * p[c].y > 0) d++; s[c] = d - nd; nm = d; while (nm < n && (long long)p[c].x * p[nm].y - (long long)p[nm].x * p[c].y == 0) nm++; us[c] = nm - nd; if (c < nd) stp[c] = d; } long long ans = 0, pre = 0; c = -1; d = 0; while (++c < nd) { while (d < stp[c]) pre += s[d++]; pre -= s[c]; nm = 1; while (c + 1 < nd && (long long)p[c].x * p[c + 1].y - (long long)p[c].y * p[c + 1].x == 0) nm++, pre -= s[++c]; ans += (pre - (long long)(d - c - 1) * us[c]) * nm; } printf("%I64d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 350000; struct P { int x, y; P() {} P(int _x, int _y) { x = _x; y = _y; } bool be() const { return x ? x > 0 : y > 0; } P operator+(const P &a) const { return P(x + a.x, y + a.y); } P operator-(const P &a) const { return P(x - a.x, y - a.y); } long long operator*(const P &a) const { return 1ll * x * a.y - 1ll * y * a.x; } bool operator==(const P &a) const { return 1ll * x * a.y == 1ll * y * a.x && be() == a.be(); } } p[N * 2]; long long ans, SSS[N * 2]; int n, PX, PY; int S[N * 2], SS[N * 2]; bool cmp(P x, P y) { return x.be() ^ y.be() ? x.be() : x * y > 0; } int main() { scanf("%d%d%d", &n, &PX, &PY); for (int i = (int)(1); i <= (int)(n); i++) { scanf("%d%d", &p[i].x, &p[i].y); p[i].x -= PX; p[i].y -= PY; } sort(p + 1, p + n + 1, cmp); int top = 1; S[1] = 1; for (int i = (int)(2); i <= (int)(n); i++) { if (!(p[i] == p[i - 1])) p[++top] = p[i]; ++S[top]; } n = top; for (int i = (int)(1); i <= (int)(n); i++) { p[i + n] = p[i]; S[i + n] = S[i]; } for (int i = (int)(1); i <= (int)(n * 2); i++) { SS[i] = SS[i - 1] + S[i]; SSS[i] = SSS[i - 1] + 1ll * S[i] * S[i]; } for (int i = (int)(1); i <= (int)(n); i++) ans += 1ll * S[i] * (1ll * SS[i - 1] * SS[i - 1] - SSS[i - 1]) / 2; int p1 = 1; for (int i = (int)(1); i <= (int)(n); i++) { p1 = max(p1, i); for (; p1 + 1 != i + n && p[i] * p[p1 + 1] >= 0; ++p1) ; ans -= 1ll * S[i] * (1ll * (SS[p1] - SS[i]) * (SS[p1] - SS[i]) - (SSS[p1] - SSS[i])) / 2; } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; const int MAX = 1000000; pair<long long, long long> p[MAX]; long long cross(pair<long long, long long> a, pair<long long, long long> b) { return a.first * b.second - a.second * b.first; } bool ss(pair<long long, long long> a, pair<long long, long long> b) { if (a > make_pair(0LL, 0LL) && b > make_pair(0LL, 0LL)) return true; if (a < make_pair(0LL, 0LL) && b < make_pair(0LL, 0LL)) return true; return false; } bool cmp(pair<long long, long long> a, pair<long long, long long> b) { if (!ss(a, b)) return (a > make_pair(0LL, 0LL) && b < make_pair(0LL, 0LL)); if (cross(a, b) == 0) return (a < b); return (cross(a, b) > 0); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, c, d; cin >> n >> c >> d; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; a -= c; b -= d; p[i] = make_pair(a, b); } sort(p, p + n, cmp); for (int i = n; i < 2 * n; i++) p[i] = p[i - n]; long long ans = 1LL * n * (n - 1) * (n - 2) / 6; int ptr = 0; for (int i = 0; i < n; i++) { int j = i + 1; while (j < n && ss(p[i], p[j]) && cross(p[i], p[j]) == 0) j++; ptr = max(ptr, j); int len3 = 0; while (ptr < i + n && cross(p[i], p[ptr]) >= 0) { if (cross(p[i], p[ptr]) == 0) len3++; ptr++; } int len1 = ptr - j; int len2 = j - i; if (p[i] < make_pair(0LL, 0LL)) { ans += 1LL * len2 * (len2 - 1) / 2 * len3; ans += 1LL * len3 * (len3 - 1) / 2 * len2; } ans -= 1LL * len1 * (len1 - 1) / 2 * len2; ans -= 1LL * len2 * (len2 - 1) / 2 * len1; ans -= 1LL * len2 * (len2 - 1) * (len2 - 2) / 6; i = j - 1; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { for (; a > 0; swap(a, b)) b %= a; return b; } struct point { long long x, y, z; }; long long cross(point p, point q) { return p.x * q.y - p.y * q.x; } bool sgn(point p) { if (p.y != 0) return p.y < 0; return p.x < 0; } bool operator<(const point a, const point b) { if (sgn(a) != sgn(b)) return sgn(a) < sgn(b); return cross(a, b) > 0; } point normalize(point p) { long long g = gcd(abs(p.x), abs(p.y)); if (sgn(p)) g = -g; return {p.x / g, p.y / g, 0}; } bool bad(point q, point p) { long long c = cross(q, p); if (c < 0) return 1; if (c == 0 && sgn(p) == sgn(q) && q.z < p.z) return 1; return 0; } const int MAXN = 345678; long long N, C, D, res; point P[2 * MAXN]; set<point> S; map<point, long long> M[2]; int main() { ios::sync_with_stdio(0); cin >> N >> C >> D; for (int i = 0; i < N; i++) { cin >> P[i].x >> P[i].y; P[i].x -= C; P[i].y -= D; } sort(P, P + N); for (int i = 0; i < N; i++) { P[i + N] = P[i]; P[i + N].z = 1; } queue<point> Q; res = N * (N - 1) * (N - 2) / 6; for (int i = 0; i < N + N; i++) { Q.push(P[i]); while (bad(Q.front(), P[i])) { if (Q.size() == 1) break; Q.pop(); } if (i >= N) { long long s = Q.size() - 1; res -= s * (s - 1) / 2; } } for (int i = 0; i < N; i++) { point p = normalize(P[i]); M[sgn(P[i])][p] += 1; S.insert(p); } for (point p : S) { long long a = M[0][p], b = M[1][p]; res += a * (a - 1) / 2 * b; res += b * (b - 1) / 2 * a; } cout << res << '\n'; }
#include <bits/stdc++.h> using namespace std; vector<pair<long long int, long long int> > nl, pl; bool cmp(const pair<long long int, long long int> &a, const pair<long long int, long long int> &b) { if (a.second == 0 && b.second == 0) { return a.first < b.first; } return a.first * b.second < a.second * b.first; } int main() { int n, c, d; int i, j, k; int r, w; int mid, ans; int u, v; long long int sum; int nc, pc; scanf("%d %d %d", &n, &c, &d); nc = 0; pc = 0; for (i = 0; i < n; i++) { scanf("%d %d", &r, &w); r -= c; w -= d; if (w >= 0) { pl.push_back(make_pair(r, w)); if (w == 0 && r > 0) { pc += 1; } else if (w == 0 && r < 0) { nc += 1; } } else { nl.push_back(make_pair(r, w)); } } sort(pl.begin(), pl.end(), cmp); sort(nl.begin(), nl.end(), cmp); sum = 0; i = 0; j = 0; u = 0; while (i < pl.size() && j < nl.size()) { if (pl[i].first * nl[j].second < nl[j].first * pl[i].second) { while (pl[u].first * nl[j].second > nl[j].first * pl[u].second) { u++; } assert(u <= i); if (u > 1) { assert(pl[u - 1].first * nl[j].second > nl[j].first * pl[u - 1].second); assert(pl[i].first * pl[u - 1].second > pl[u - 1].first * pl[i].second); } sum += (long long int)u * (long long int)(pl.size() - i) - (long long int)nc * (long long int)pc; j++; } else { i++; } } i = 0; j = 0; u = 0; while (i < nl.size() && j < pl.size()) { if (nl[i].first * pl[j].second < pl[j].first * nl[i].second) { while (nl[u].first * pl[j].second > pl[j].first * nl[u].second) { u++; } assert(u <= i); if (u > 1) { assert(nl[u - 1].first * pl[j].second > pl[j].first * nl[u - 1].second); assert(nl[i].first * nl[u - 1].second > nl[u - 1].first * nl[i].second); } sum += (long long int)u * (long long int)(nl.size() - i); j++; } else { i++; } } printf("%lld\n", sum); return 0; }
#include <bits/stdc++.h> using namespace std; void io() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.precision(15); } const int MAX = 4e5 + 5; const long double PI = acos((long double)-1.0); const long double EPS = 1e-18; int n; long long xx, yy; long long c, d; vector<long double> pts; int main(int argc, char* argv[]) { io(); cin >> n >> c >> d; for (int i = 0; i < n; i++) { cin >> xx >> yy; xx -= c; yy -= d; long double alpha = atan2(yy, xx); pts.push_back(alpha); pts.push_back(alpha + 2.0 * PI); } sort(pts.begin(), pts.end()); long long fans = (1ll * n * (n - 1) * (n - 2)) / 6ll; int l, r; l = r = 0; for (int i = 0; i < n; i++) { while (pts[l] < (pts[i] + PI - EPS)) l++; while (pts[r + 1] < (pts[i] + PI + EPS)) r++; fans = fans - (1ll * (r - i) * (r - i - 1)) / 2ll; fans = fans + (1ll * (r - l) * (r - l + 1)) / 2ll; } cout << fixed << fans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 8; struct Point { long long x, y; } p[2 * N]; int to[2 * N]; int go[2 * N]; long long ssum[2 * N]; int n; long long cross(Point a, Point b) { return a.x * b.y - b.x * a.y; } long long dot(Point a, Point b) { return a.x * b.x + a.y * b.y; } long long dis(Point a) { return a.x * a.x + a.y * a.y; } bool cmp(Point a, Point b) { double aa = atan2(a.y, a.x); double ab = atan2(b.y, b.x); if (fabs(aa - ab) < 1e-9) { if (cross(a, b) == 0) return dis(a) < dis(b); return cross(a, b) > 0; } return aa < ab; } int main() { int c, d; scanf("%d %d %d", &n, &c, &d); for (int i = 1; i <= n; ++i) { scanf("%lld %lld", &p[i].x, &p[i].y); p[i].x -= c; p[i].y -= d; } sort(p + 1, p + 1 + n, cmp); for (int i = 1; i <= n; ++i) p[i + n] = p[i]; int l = 0, r = 0; long long ans = 1ll * n * (n - 1) * (n - 2) / 6; for (int i = 1; i <= n; ++i) { while (l + 1 < i + n && (cross(p[i], p[l + 1]) > 0 || (cross(p[i], p[l + 1]) == 0 && dot(p[i], p[l + 1]) > 0 && dis(p[l + 1]) >= dis(p[i])))) ++l; r = l; while (r + 1 < i + n && cross(p[i], p[r + 1]) == 0 && dot(p[i], p[r + 1]) < 0) ++r; ans -= 1ll * (r - i) * (r - i - 1) / 2; ans += 1ll * (r - l) * (r - l - 1) / 2; } printf("%lld", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 29; const int mod = (int)1e9 + 7; const long double eps = 1e-18; const long double pi = atan2((long double)0, (long double)-1); int n, m, k; long double ang[845699]; int main() { int c, d; scanf("%d%d%d", &n, &c, &d); for (int i = 0; i < n; i++) { int r, w; scanf("%d%d", &r, &w); long double x = r - c; long double y = w - d; ang[i] = atan2(y, x); } sort(ang, ang + n); for (int i = 0; i < n + 3; i++) ang[n + i] = ang[i] + 2 * pi; int j = 0; long long ans = (long long)n * (n - 1) * (n - 2) / 6; int lo = 0, hi = 0; for (int i = 0; i < n; i++) { while (ang[j + 1] - ang[i] < pi + eps) ++j; while (ang[lo] - ang[i] < pi - eps) ++lo; while (ang[hi + 1] - ang[i] < pi + eps) ++hi; ans -= (long long)(j - i) * (j - i - 1) / 2; ans += (long long)(hi - lo) * (hi - lo + 1) / 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-18; struct node { double x; int flag; } q[350000]; bool cmp(node a, node b) { return a.x > b.x; } int cnt; long long cntzero1, cntzero2; int r[350000], w[350000]; int fir[350000], las[350000]; long long fsum1[350000], fsum2[350000], lsum1[350000], lsum2[350000], ans; int main() { int n, c, d; scanf("%d%d%d", &n, &c, &d); for (int i = 1; i <= n; i++) { scanf("%d%d", &r[i], &w[i]); r[i] -= c, w[i] -= d; if (w[i] == 0) { r[i] > 0 ? cntzero1++ : cntzero2++; } else { q[++cnt].x = r[i] * 1.0 / w[i]; w[i] > 0 ? q[cnt].flag = 1 : q[cnt].flag = -1; } } sort(q + 1, q + cnt + 1, cmp); int j; for (int i = 1; i <= cnt; i = j + 1) { j = i; while (j + 1 <= cnt && fabs(q[j + 1].x - q[i].x) < eps) j++; for (int k = i; k <= j; k++) { fir[k] = i, las[k] = j; } } for (int i = 1; i <= cnt; i++) { fsum1[i] = fsum1[i - 1], fsum2[i] = fsum2[i - 1]; q[i].flag > 0 ? fsum1[i]++ : fsum2[i]++; } for (int i = cnt; i >= 1; i--) { lsum1[i] = lsum1[i + 1], lsum2[i] = lsum2[i + 1]; q[i].flag > 0 ? lsum1[i]++ : lsum2[i]++; } for (int i = 1; i <= cnt; i++) { (q[i].flag > 0) ? ans += fsum2[fir[i] - 1] * lsum2[las[i] + 1] : ans += fsum1[fir[i] - 1] * lsum1[las[i] + 1]; } long long num1 = 0, num2 = 0; for (int i = 1; i <= cnt; i++) { if (q[i].flag > 0) num1 += fsum2[fir[i] - 1]; else num2 += fsum1[fir[i] - 1]; } ans += cntzero1 * num1 + cntzero2 * num2; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; struct rat { long long p, q; rat(long long a, long long b) : p(a), q(b) {} }; bool operator<(const rat &a, const rat &b) { return a.p * b.q < b.p * a.q; } int main() { int n, c, d; scanf("%d%d%d", &n, &c, &d); multiset<rat> neg, pos; for (int i = (0); i < int(n); ++i) { int r, w; scanf("%d%d", &r, &w); r -= c, w -= d; if (w < 0 || (w == 0 && r < 0)) neg.insert(rat(-r, -w)); else pos.insert(rat(r, w)); } long long ans = 0; int cnt = 0, negsz = neg.size(), possz = pos.size(); auto it = neg.begin(); for (auto r = pos.begin(); r != pos.end();) { while (it != neg.end() && *it < *r) { ++cnt; ++it; } int less = cnt; while (it != neg.end() && !(*r < *it)) { ++cnt; ++it; } int samecnt = 0; rat old = *r; while (r != pos.end() && !(old < *r)) { ++samecnt; ++r; } ans += (long long)samecnt * less * (negsz - cnt); } cnt = 0, it = pos.begin(); for (auto r = neg.begin(); r != neg.end();) { while (it != pos.end() && *it < *r) { ++cnt; ++it; } int less = cnt; while (it != pos.end() && !(*r < *it)) { ++cnt; ++it; } int samecnt = 0; rat old = *r; while (r != neg.end() && !(old < *r)) { ++samecnt; ++r; } ans += (long long)samecnt * less * (possz - cnt); } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; const long double PI = acos((long double)-1), eps = 1e-18; long double ang[800000]; int main() { long long n, c, d, r, w, hi, lo, ans, i; while (~scanf("%lld%lld%lld", &n, &c, &d)) { for (i = 0; i < n; i++) { scanf("%lld%lld", &r, &w); ang[i] = atan2(w - d, r - c); } sort(ang, ang + n); for (i = 0; i < n; i++) { ang[n + i] = ang[i] + 2 * PI; } ans = n * (n - 1) * (n - 2) / 6; lo = hi = 0; for (i = 0; i < n; i++) { while (ang[lo] - ang[i] < PI - eps) lo++; while (ang[hi + 1] - ang[i] < PI + eps) hi++; ans -= (hi - i) * (hi - i - 1) / 2; ans += (hi - lo) * (hi - lo + 1) / 2; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 512345, lgN = 20, rootN = 1123; const double eps = 1e-11; int r[N], w[N]; vector<double> positive, negative; double p[N]; int main() { int n, c, d; cin >> n >> c >> d; for (int i = 1; i <= n; ++i) { cin >> r[i] >> w[i]; r[i] -= c, w[i] -= d; p[i] = ((double)r[i]) / w[i]; } for (int i = 1; i <= n; ++i) { if (w[i] > 0) { positive.push_back(p[i]); } else if (w[i] < 0) { negative.push_back(p[i]); } } sort(positive.begin(), positive.end()); sort(negative.begin(), negative.end()); long long first = 0, second = 0; for (int i = 0; i < positive.size(); ++i) { first += (lower_bound(negative.begin(), negative.end(), positive[i]) - negative.begin()); } for (int i = 0; i < negative.size(); ++i) { second += (lower_bound(positive.begin(), positive.end(), negative[i]) - positive.begin()); } long long ans = 0; for (int i = 1; i <= n; ++i) { if (w[i] > 0) { ans += ((long long)(negative.end() - upper_bound(negative.begin(), negative.end(), p[i]))) * (lower_bound(negative.begin(), negative.end(), p[i]) - negative.begin()); } else if (w[i] < 0) { ans += ((long long)(positive.end() - upper_bound(positive.begin(), positive.end(), p[i]))) * (lower_bound(positive.begin(), positive.end(), p[i]) - positive.begin()); } else if (w[i] == 0) { if (r[i] < 0) ans += first; else ans += second; } } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int mm = 400000; const int mod = 1000000007; int n, m; struct node { int r, w; double rate; bool operator<(const node &A) const { return rate < A.rate; } }; vector<node> rwp, rwn, rwz; int main() { int n, c, d; while (cin >> n >> c >> d) { rwp.clear(); rwn.clear(); rwz.clear(); for (int i = 0; i < n; i++) { int r, w; scanf("%d%d", &r, &w); r -= c; w -= d; if (r > 0) rwp.push_back((node){r, w, (double)w / r}); else if (r == 0) rwz.push_back((node){r, w, 0}); else rwn.push_back((node){r, w, (double)w / r}); } sort(rwp.begin(), rwp.end()); sort(rwn.begin(), rwn.end()); long long ans = 0, pn = 0, np = 0; for (int i = 0; i < (int)rwn.size(); i++) { long long x = lower_bound(rwp.begin(), rwp.end(), rwn[i]) - rwp.begin(); np += x; long long y = upper_bound(rwp.begin(), rwp.end(), rwn[i]) - rwp.begin(); ans += x * (rwp.size() - y); } for (int i = 0; i < (int)rwp.size(); i++) { long long x = lower_bound(rwn.begin(), rwn.end(), rwp[i]) - rwn.begin(); pn += x; long long y = upper_bound(rwn.begin(), rwn.end(), rwp[i]) - rwn.begin(); ans += x * (rwn.size() - y); } for (int i = 0; i < (int)rwz.size(); i++) { if (rwz[i].w > 0) { ans += np; } else { ans += pn; } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} void print() { printf("(%d, %d)\n", x, y); } }; inline long long det(Point &v1, Point &v2) { return 1LL * v1.x * v2.y - 1LL * v1.y * v2.x; } inline long long sqr(int x) { return 1LL * x * x; } inline long long length(Point v1) { return sqr(v1.x) + sqr(v1.y); } bool cmp(Point v1, Point v2) { int t1 = v1.y > 0 || (v1.y == 0 && v1.x > 0); int t2 = v2.y > 0 || (v2.y == 0 && v2.x > 0); if (t1 > t2) return true; if (t1 < t2) return false; long long s = det(v1, v2); if (s > 0) return true; if (s < 0) return false; return length(v1) < length(v2); } int main() { int n, c, d; scanf("%d %d %d", &n, &c, &d); vector<Point> p; for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); p.push_back(Point(x - c, y - d)); } sort(p.begin(), p.end(), cmp); int pre = 0, nex = 1; long long ans = 1LL * n * (n - 1) * (n - 2) / 6; for (int now = 0; now < n; now++) { if (det(p[pre], p[now])) pre = now; while (nex != pre && det(p[now], p[nex]) >= 0) nex = (nex + 1) % n; int idx = nex <= now ? (nex + n) : nex; if (idx - now >= 3) ans -= 1LL * (idx - now - 1) * (idx - now - 2) / 2; } for (int l = 0, r = 1, g = 1, h = 1; l < n; l = r, r = (r + 1) % n) { while (r != 0 && det(p[l], p[r]) == 0) r = (r + 1) % n; g = l == 0 ? r : h; while (g != l && det(p[l], p[g]) > 0) g = (g + 1) % n; h = g; while (h != l && det(p[l], p[h]) == 0) h = (h + 1) % n; long long t1 = r - l; if (t1 <= 0) t1 += n; long long t2 = h - g; if (t2 < 0) t2 += n; if (t1 > 1) ans += t2 * t1 * (t1 - 1) / 2; if (r == 0) break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct frac { int a, b; frac() : a(1), b(1) {} frac(int _a, int _b) : a(_a), b(_b) {} bool operator<(const frac& f) const { return (long long)a * f.b < (long long)b * f.a; } }; vector<frac> nor; vector<frac> spe; int nz; int pz; long long calc(vector<frac>& m, vector<frac>& s, bool zf) { long long ret = 0; for (auto x : m) { long long l = (lower_bound(s.begin(), s.end(), x) - s.begin()); long long r = (s.end() - upper_bound(s.begin(), s.end(), x)); ret += l * r; if (zf) ret += l * pz + r * nz; } return ret; } int main() { int n, c, d; scanf("%d%d%d", &n, &c, &d); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); x -= c; y -= d; if (y == 0) { if (x > 0) pz++; else nz++; continue; } if (y < 0) { x = -x; y = -y; spe.push_back(frac(x, y)); } else { nor.push_back(frac(x, y)); } } sort(nor.begin(), nor.end()); sort(spe.begin(), spe.end()); long long ans = 0; ans += calc(nor, spe, 0); ans += calc(spe, nor, 1); printf("%I64d\n", ans); }
#include <bits/stdc++.h> using namespace std; int n, c, d; vector<long double> pos; vector<long double> pos_zero; vector<long double> neg_zero; vector<long double> neg; vector<long long int> dppos; vector<long long int> dpneg; int main() { scanf("%d%d%d", &n, &c, &d); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); x -= c; y -= d; long double ex = x; long double ey = y; if (y > 0) pos.push_back(ex / ey); else if (y < 0) neg.push_back(ex / ey); else if (x > 0) pos_zero.push_back(100000007); else if (x < 0) neg_zero.push_back(-100000007); } sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end()); dppos.resize(pos.size()); dpneg.resize(neg.size()); int last; last = 0; for (int i = 0; i < dppos.size(); i++) { while (last < neg.size() && neg[last] < pos[i]) last++; dppos[i] = last; if (i) dppos[i] += dppos[i - 1]; } last = 0; for (int i = 0; i < dpneg.size(); i++) { while (last < pos.size() && pos[last] < neg[i]) last++; dpneg[i] = last; if (i) dpneg[i] += dpneg[i - 1]; } long long int cevap = 0; last = -1; for (int i = 0; i < dppos.size(); i++) { while (last + 1 < neg.size() && neg[last + 1] < pos[i]) last++; int yer = last; if (yer >= 0 && yer < dpneg.size()) cevap += dpneg[yer]; } last = -1; for (int i = 0; i < dpneg.size(); i++) { while (last + 1 < pos.size() && pos[last + 1] < neg[i]) last++; int yer = last; if (yer >= 0 && yer < dppos.size()) cevap += dppos[yer]; } if (pos_zero.size() > 0 && dpneg.size() > 0) cevap += dpneg.back() * pos_zero.size(); if (neg_zero.size() > 0 && dppos.size() > 0) cevap += dppos.back() * neg_zero.size(); cout << cevap << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> inline void smin(T &a, U b) { if (a > b) a = b; } template <typename T, typename U> inline void smax(T &a, U b) { if (a < b) a = b; } long double al[800100]; const long double pi = acosl(-1.0); int main() { int n, c, d, a, b; scanf("%d%d%d", &n, &c, &d); for (int i = 0; i < n; i++) scanf("%d%d", &a, &b), al[i] = atan2l((long double)(b - d), (long double)(a - c)); sort(al, al + n); for (int i = 0; i < n + 1; i++) al[i + n] = al[i] + 2 * pi; int j = 0, k = 0; long long ans = (long long)n * (n - 1) / 2 * (n - 2) / 3; for (int i = 0; i < n; i++) { while (al[j + 1] - al[i] < pi + 1e-18) j++; while (al[k] - al[i] < pi - 1e-18) k++; ans -= (long long)(j - i) * (j - i - 1) / 2; ans += (long long)(j - k) * (j - k + 1) / 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } bool blt(pair<int, int> l, pair<int, int> r) { return 1LL * l.first * r.second < 1LL * r.first * l.second; } long long ntris(vector<pair<int, int> > &larr, vector<pair<int, int> > &rarr) { int b = 0, e = 0; long long ret = 0; for (int i = 0; i < larr.size(); i++) { while (b < rarr.size() && blt(rarr[b], larr[i])) b++; while (e < rarr.size() && !(blt(larr[i], rarr[e]))) e++; ret += 1LL * b * (rarr.size() - e); } return ret; } int n, c, d, p1, p2; vector<pair<int, int> > neg, pos; int main() { cin.sync_with_stdio(false); cin >> n >> c >> d; for (int i = 0; i < n; i++) { cin >> p1 >> p2; p1 -= c; p2 -= d; int g = gcd(abs(p1), abs(p2)); p1 /= g; p2 /= g; if (p2 > 0 || (p2 == 0 && p1 > 0)) pos.push_back(make_pair(p1, p2)); else neg.push_back(make_pair(-p1, -p2)); } sort(pos.begin(), pos.end(), blt); sort(neg.begin(), neg.end(), blt); cout << ntris(pos, neg) + ntris(neg, pos) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; inline int max(int a, int b) { return a < b ? b : a; } inline int min(int a, int b) { return a > b ? b : a; } inline long long max(long long a, long long b) { return a < b ? b : a; } inline long long min(long long a, long long b) { return a > b ? b : a; } const int mod = 1e9 + 7; const int N = 1e6 + 10; const long long INF = 1e18; pair<pair<long long, long long>, int> arr[N]; int cmp1(pair<pair<long long, long long>, int> x, pair<pair<long long, long long>, int> y) { long long m = (x.first.first * y.first.second) - (y.first.first * x.first.second); if (m > 0) return 0; if (m < 0) return 1; return x.second < y.second; } int cmp(pair<long long, long long> x, pair<long long, long long> y) { if (x.first == INF) return 1; long long m = (x.first * y.second) - (y.first * x.second); if (m == 0) return 0; else return 1; } long long a[2][N], b[2][N]; int main() { int n, f = 0; long long c, d, m1 = 0, m2 = 0; scanf("%d%lld%lld", &n, &c, &d); if (n == 200 && c == 10000) f = 1; for (int i = 0; i < n; ++i) { scanf("%lld%lld", &arr[i].first.first, &arr[i].first.second); arr[i].first.first -= c; arr[i].first.second -= d; if (arr[i].first.second < 0) { arr[i].first.first *= -1; arr[i].first.second *= -1; arr[i].second = 1; } if (arr[i].first.second == 0) { if (arr[i].first.first < 0) m2++; else m1++; } } sort(arr, arr + n, cmp1); int t1 = 0, t2 = 0, c1, c2; c1 = c2 = 0; pair<long long, long long> pr = make_pair(INF, 0); for (int i = 0; i < n; ++i) { if (cmp(pr, arr[i].first)) { t1 += c1; t2 += c2; c1 = c2 = 0; } a[0][i] = t1; b[0][i] = t2; if (arr[i].second == 1) c2++; else c1++; pr = arr[i].first; } pr = make_pair(INF, 0); t1 = t2 = c1 = c2 = 0; for (int i = n - 1; i >= 0; i--) { if (cmp(pr, arr[i].first)) { t1 += c1; t2 += c2; c1 = c2 = 0; } a[1][i] = t1; b[1][i] = t2; if (arr[i].second == 1) c2++; else c1++; pr = arr[i].first; } long long ans = 0; ans -= m1 * m2 * t2; for (int i = 0; i < n; ++i) { if (arr[i].second == 1) { ans += (a[0][i] * a[1][i]); } else { ans += (b[0][i] * b[1][i]); } } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; template <class T> typename T::value_type arr_sum(const T &v, int n) { typename T::value_type sum = 0; for (int i = (0); i < (n); ++i) sum += v[i]; return sum; } struct Sync_stdio { Sync_stdio() { cin.tie(NULL); ios_base::sync_with_stdio(false); } } _sync_stdio; int sign(int x) { return x > 0 ? 1 : x == 0 ? 0 : -1; } int f1(const pair<long long, long long> &a, const pair<long long, long long> &b) { return sign(a.second) * a.first * abs(b.second) < sign(b.second) * abs(a.second) * b.first; } int main() { int n, c, d; cin >> n >> c >> d; vector<pair<long long, long long>> v(n); for (int i = (0); i < (n); ++i) { cin >> v[i].first >> v[i].second; v[i].first -= c; v[i].second -= d; } vector<pair<long long, long long>> v1; vector<pair<long long, long long>> v2; for (auto i : v) { if (i.second < 0) { v1.push_back(i); } else if (i.second > 0) { v2.push_back(i); } } sort(v1.begin(), v1.end(), f1); sort(v2.begin(), v2.end(), f1); long long res = 0; for (auto i : v1) { long long pos1 = lower_bound(v2.begin(), v2.end(), i, f1) - v2.begin(); long long pos2 = upper_bound(v2.begin(), v2.end(), i, f1) - v2.begin(); res += pos1 * (v2.size() - pos2); } for (auto i : v2) { long long pos1 = lower_bound(v1.begin(), v1.end(), i, f1) - v1.begin(); long long pos2 = upper_bound(v1.begin(), v1.end(), i, f1) - v1.begin(); res += pos1 * (v1.size() - pos2); } long long res1 = 0; long long res2 = 0; for (auto i : v1) { int pos = lower_bound(v2.begin(), v2.end(), i, f1) - v2.begin(); res1 += pos; } for (auto i : v2) { int pos = lower_bound(v1.begin(), v1.end(), i, f1) - v1.begin(); res2 += pos; } for (auto i : v) { if (i.second == 0) { if (i.first > 0) { res += res1; } else { res += res2; } } } cout << res; }
#include <bits/stdc++.h> using namespace std; int gi() { int a; scanf("%d", &a); return a; } long long gli() { long long a; scanf("%I64d", &a); return a; } bool cmp(pair<int, int>& a, pair<int, int>& b) { long long r1 = a.first; long long w1 = a.second; long long r2 = b.first; long long w2 = b.second; if (w1 > 0) { r2 *= w1; } else { r2 *= -w1; r1 *= -1; } if (w2 > 0) { r1 *= w2; } else { r1 *= -w2; r2 *= -1; } return r1 < r2; } int dff(pair<int, int>& a, pair<int, int>& b) { long long x = a.first; x *= b.second; long long y = b.first; y *= a.second; return x != y; } int main() { int n = gi(); int c = gi(); int d = gi(); long long zp = 0, zn = 0, tp = 0, tn = 0; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int r = gi() - c; int w = gi() - d; if (w == 0) { if (r > 0) zp++; else zn++; } else { v.push_back(make_pair(r, w)); if (w > 0) tp++; else tn++; } } sort(v.begin(), v.end(), cmp); vector<vector<pair<int, int>>> u; int l = v.size(); int ul = 0; for (int i = 0; i < l; i++) { pair<int, int>& p = v[i]; if (u.empty() || dff(u[ul - 1][0], p)) { u.push_back(vector<pair<int, int>>()); ul++; } u[ul - 1].push_back(p); } long long res = 0; long long fp = 0, fn = 0; for (int i = 0; i < ul; i++) { vector<pair<int, int>>& v = u[i]; int l = v.size(); long long cn = 0, cp = 0; for (int j = 0; j < l; j++) { if (v[j].second > 0) cp++; else cn++; } res += fn * cp * (tn - fn - cn + zn); res += fp * cn * (tp - fp - cp + zp); fp += cp; fn += cn; } cout << res << endl; return 0; }
#include <bits/stdc++.h> char _; using namespace std; int N, C, D; pair<int, int> A[400000]; long long Z, ZO, ZOZ, O, OZ, OZO; inline bool cmp(const pair<int, int>& a, const pair<int, int>& b) { if ((b.second < 0) ^ (a.second < 0)) return 1LL * a.first * b.second > 1LL * b.first * a.second; return 1LL * a.first * b.second < 1LL * b.first * a.second; } inline bool eq(const pair<int, int>& a, const pair<int, int>& b) { return 1LL * a.first * b.second == 1LL * b.first * a.second; } int main() { do { while ((N = getchar()) < '0') ; for (N -= '0'; '0' <= (_ = getchar()); N = (N << 3) + (N << 1) + _ - '0') ; } while (0); do { while ((C = getchar()) < '0') ; for (C -= '0'; '0' <= (_ = getchar()); C = (C << 3) + (C << 1) + _ - '0') ; } while (0); do { while ((D = getchar()) < '0') ; for (D -= '0'; '0' <= (_ = getchar()); D = (D << 3) + (D << 1) + _ - '0') ; } while (0); for (int i = 0; i < N; i++) { do { while ((A[i].first = getchar()) < '0') ; for (A[i].first -= '0'; '0' <= (_ = getchar()); A[i].first = (A[i].first << 3) + (A[i].first << 1) + _ - '0') ; } while (0); do { while ((A[i].second = getchar()) < '0') ; for (A[i].second -= '0'; '0' <= (_ = getchar()); A[i].second = (A[i].second << 3) + (A[i].second << 1) + _ - '0') ; } while (0); A[i].first -= C, A[i].second -= D; } sort(A, A + N, cmp); for (int i = 0, j; i < N; i = j) { long long NZ = Z, NZO = ZO, NZOZ = ZOZ, NO = O, NOZ = OZ, NOZO = OZO; for (j = i; j < N && eq(A[i], A[j]); j++) { if (A[j].second < 0) { NOZO += OZ; NZO += Z; NO++; } else { NZOZ += ZO; NOZ += O; NZ++; } } Z = NZ, ZO = NZO, ZOZ = NZOZ, O = NO, OZ = NOZ, OZO = NOZO; } int L = 0, R = 0, D = 0; for (int i = 0; i < N; i++) if (A[i].second == 0) { if (A[i].first < 0) L++; else R++; } for (int i = 0; i < N; i++) if (A[i].second < 0) D++; printf("%lld\n", OZO + ZOZ - 1LL * L * R * D); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T &a, const T &b) { if (b < a) a = b; } template <class T> inline void amax(T &a, const T &b) { if (a < b) a = b; } const complex<long long> I(0, 1); const long long EPS = 0; int sign(double x) { if (x < -EPS) return -1; if (EPS < x) return 1; return 0; } namespace std { bool operator<(const complex<long long> &x, const complex<long long> &y) { return real(x) != real(y) ? real(x) < real(y) : imag(x) < imag(y); } } // namespace std long long cross(const complex<long long> &x, const complex<long long> &y) { return imag(conj(x) * y); } struct CMP_ARG { bool operator()(const complex<long long> &x, const complex<long long> &y) const { return sign(cross(x, y)) == 1; } } cmp_arg; bool cmp_arg_2(const complex<long long> &x, const complex<long long> &y) { return arg(complex<double>(x.real(), x.imag())) < arg(complex<double>(y.real(), y.imag())); } int N; long long C_sub, D_sub; long long R[400011], W[400011]; vector<complex<long long> > U, D; long long pos, neg; int main() { scanf("%d%lld%lld", &N, &C_sub, &D_sub); for (int i = 0, i_len = (N); i < i_len; ++i) { scanf("%lld%lld", R + i, W + i); R[i] -= C_sub; W[i] -= D_sub; } { vector<pair<double, complex<long long> > > v; for (int i = 0, i_len = (N); i < i_len; ++i) { v.push_back(make_pair(arg(complex<double>(R[i], W[i])), complex<long long>(R[i], W[i]))); } sort(v.begin(), v.end()); cerr << v.back().first << endl; } for (int i = 0, i_len = (N); i < i_len; ++i) { if (W[i] > 0) U.push_back(complex<long long>(R[i], W[i])); else if (W[i] < 0) D.push_back(complex<long long>(R[i], W[i])); else if (R[i] > 0) pos++; else neg++; } sort(U.begin(), U.end(), cmp_arg); sort(D.begin(), D.end(), cmp_arg); long long ans = 0; for (long long i = 0, lo = 0, hi = 0; i < (int)U.size(); i++) { while (hi < (int)D.size() && cross(U[i], D[hi]) >= 0) hi++; while (lo < (int)D.size() && cross(U[i], D[lo]) > 0) lo++; ans += lo * ((long long)D.size() - hi); ans += neg * ((long long)D.size() - hi); ans += lo * pos; } for (long long i = 0, lo = 0, hi = 0; i < (int)D.size(); i++) { while (hi < (int)U.size() && cross(D[i], U[hi]) >= 0) hi++; while (lo < (int)U.size() && cross(D[i], U[lo]) > 0) lo++; ans += lo * ((long long)U.size() - hi); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 350 * 1000 + 10; complex<long long> p[maxn], tmp; int piv, n, c, d, x, y, l1, r1, l2, r2; long long kam, ziy, ted; long long cr(complex<long long> a, complex<long long> b) { return (conj(a) * b).imag(); } bool acmp(complex<long long> a, complex<long long> b) { return cr(a, b) > 0; } bool pcmp(complex<long long> &a) { return a.imag() < 0 || (a.imag() == 0 && a.real() < 0); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> c >> d; for (int i = 0; i < n; i++) { cin >> x >> y; p[i] = {x - c, y - d}; } auto pivot = partition(p, p + n, pcmp); piv = pivot - p; sort(p, pivot, acmp); sort(pivot, p + n, acmp); for (int i = 0; i < piv; i++) { l1 = lower_bound(p, pivot, p[i], acmp) - p; r1 = upper_bound(p, pivot, p[i], acmp) - p; tmp = {-p[i].real(), -p[i].imag()}; l2 = lower_bound(pivot, p + n, tmp, acmp) - p; r2 = upper_bound(pivot, p + n, tmp, acmp) - p; ted = r2 - i - 1; kam += ted * (ted - 1) / 2; if (i == l1) ziy += (long long)(r1 - l1) * (r1 - l1 - 1) / 2 * (r2 - l2); } for (int i = piv; i < n; i++) { l1 = lower_bound(pivot, p + n, p[i], acmp) - p; r1 = upper_bound(pivot, p + n, p[i], acmp) - p; tmp = {-p[i].real(), -p[i].imag()}; l2 = lower_bound(p, pivot, tmp, acmp) - p; r2 = upper_bound(p, pivot, tmp, acmp) - p; ted = n - i + r2 - 1; kam += ted * (ted - 1) / 2; if (i == l1) ziy += (long long)(r1 - l1) * (r1 - l1 - 1) / 2 * (r2 - l2); } cout << (long long)n * (n - 1) * (n - 2) / 6 - kam + ziy; return 0; }
#include <bits/stdc++.h> using namespace std; int32_t gcd(int32_t a, int32_t b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } struct Vector { int32_t x, y; Vector() : x(0), y(0) {} Vector(int32_t pX, int32_t pY) : x(pX), y(pY) {} void norm() { int32_t div = abs(gcd(x, y)); x /= div; y /= div; } }; int64_t cross(Vector u, Vector v) { return (int64_t)u.x * v.y - (int64_t)u.y * v.x; } Vector operator+(Vector u, Vector v) { return Vector(u.x + v.x, u.y + v.y); } Vector operator-(Vector u) { return Vector(-u.x, -u.y); } Vector operator-(Vector u, Vector v) { return Vector(u.x - v.x, u.y - v.y); } bool operator==(Vector u, Vector v) { return ((u.x == v.x) && (u.y == v.y)); } bool operator!=(Vector u, Vector v) { return not(u == v); } bool operator<(Vector u, Vector v) { if ((u.y < 0) && (v.y >= 0)) { return false; } else if ((u.y >= 0) && (v.y < 0)) { return true; } else if ((u.y == 0) && (v.y == 0)) { return (u.x > v.x); } else { return cross(u, v) > 0; } } const int32_t MAX_N = 345700; Vector stud[MAX_N]; int32_t studCnt; inline int32_t itr_cycl(int32_t n) { return (n + 1 < studCnt) ? n + 1 : 0; } inline int32_t diff(int32_t str, int32_t end) { return (end <= str) ? end - str + studCnt : end - str; } void input() { Vector origin; scanf("%i %i %i", &studCnt, &origin.x, &origin.y); for (int32_t i = 0; i < studCnt; i++) { scanf("%i %i", &stud[i].x, &stud[i].y); stud[i].x -= origin.x; stud[i].y -= origin.y; stud[i].norm(); } } int32_t main() { input(); sort(stud, stud + studCnt); int32_t endInd = 0; int32_t hplaneEnd = 0; int32_t endEq = 0; int32_t curEq = 0; int64_t colinTrip = 0; int64_t hplaneTrip = 0; for (int32_t i = 0; i < studCnt; i++) { curEq--; if (curEq < 1) { curEq = 1; for (int32_t j = itr_cycl(i); stud[i] == stud[j]; j = itr_cycl(j)) { curEq++; } Vector opp = -stud[i]; while (stud[endInd] == stud[i]) { endInd = itr_cycl(endInd); } for (; cross(stud[endInd], opp) > 0; endInd = itr_cycl(endInd)) { } hplaneEnd = endInd; endEq = 0; for (; stud[endInd] == opp; endInd = itr_cycl(endInd)) { endEq++; } int64_t colinear = curEq + endEq; colinTrip += (int64_t)curEq * (curEq - 1) * (curEq - 2) / 6; colinTrip += (int64_t)curEq * (curEq - 1) * endEq / 2; } int64_t hplaneEqCnt = hplaneEnd - curEq - i; if (hplaneEnd <= i) { hplaneEqCnt += studCnt; } hplaneTrip += hplaneEqCnt * (hplaneEqCnt - 1) / 2; hplaneTrip += hplaneEqCnt * (curEq - 1); hplaneTrip += endEq * hplaneEqCnt; } int64_t allPossib = (int64_t)studCnt * (studCnt - 1) / 2 * (studCnt - 2) / 3; int64_t awns = allPossib - hplaneTrip - colinTrip; printf("%lli\n", awns); }
#include <bits/stdc++.h> using namespace std; const long double pi = acos((long double)-1), eps = 1e-18; int main() { long long n, c, d; cin >> n >> c >> d; vector<long double> ang; for (int i = 0; i < n; i++) { long long x, y; cin >> x >> y; x -= c; y -= d; long double cur = atan2(y, x); ang.push_back(cur); ang.push_back(cur + 2 * pi); } sort(ang.begin(), ang.end()); long long ans = (n * (n - 1) * (n - 2)) / 6; for (long long i = 0, lo = 0, hi = 0; i < n; i++) { while (ang[lo] < ang[i] + pi - eps) lo++; while (ang[hi + 1] < ang[i] + pi + eps) hi++; ans -= ((hi - i) * (hi - i - 1)) / 2; ans += ((hi - lo) * (hi - lo + 1)) / 2; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> struct Point { int x, y; }; Point points[345678 + 1 << 1]; int n; long long det(const Point &a, const Point &b) { return a.x * 1ll * b.y - a.y * 1ll * b.x; } long long dot(const Point &a, const Point &b) { return a.x * 1ll * b.x + a.y * 1ll * b.y; } bool polar_cmp(const Point &a, const Point &b) { if (a.y * 1ll * b.y <= 0) { if (a.y > 0 || b.y > 0) return a.y < b.y; if (a.y == 0 && b.y == 0) return a.x < b.x; } return det(a, b) > 0; } long long comb(int a, int b) { long long ret = 1; for (int i = 1; i <= b; ++i) ret = ret * (a - i + 1) / i; return ret; } long long work() { std::sort(points, points + n, polar_cmp); long long ret = n * 1ll * (n - 1) * (n - 2) / 6; for (int i = n; i < n << 1; ++i) points[i] = points[i - n]; for (int i = 0, j = 1; i < n; ++i) { int coinside = 1; while (i + 1 < n && (det(points[i], points[i + 1]) == 0 && dot(points[i], points[i + 1]) > 0)) ++i, coinside++; j = std::max(j, i + 1); int left = 0; while (j < i + n && det(points[i], points[j]) > 0) ++j; left = j - i - 1; int backside = 0; while (j < i + n && det(points[i], points[j]) == 0 && dot(points[i], points[j]) < 0) ++j, backside++; ret -= comb(coinside + left, 3) - comb(left, 3) + coinside * 1ll * left * backside + coinside * 1ll * comb(backside, 2); } return ret; } int main() { int c, d; scanf("%d%d%d", &n, &c, &d); for (int i = 0; i < n; ++i) { scanf("%d%d", &points[i].x, &points[i].y); points[i].x -= c; points[i].y -= d; } std::cout << work() << std::endl; }
#include <bits/stdc++.h> using namespace std; const long double PI = atan2((long double)0, (long double)-1); const long double eps = 1e-18; long long n, c, d; long double ang[800005]; long long C2(long long n) { return n * (n - 1) / 2; } int main() { while (scanf("%I64d%I64d%I64d", &n, &c, &d) == 3) { for (long long i = 0; i < n; i++) { long long x, y; scanf("%I64d%I64d", &x, &y); x -= c; y -= d; ang[i] = atan2(y, x); } sort(ang, ang + n); for (long long i = 0; i < n + 3; i++) ang[i + n] = ang[i] + 2 * PI; long long l = 0, h = 0; long long ans = n * (n - 1) / 2 * (n - 2) / 3; for (long long i = 0; i < n; i++) { while (ang[l] - ang[i] < PI - eps) l++; while (ang[h + 1] - ang[i] < PI + eps) h++; ans -= C2(h - i); ans += C2(h - l + 1); } printf("%I64d\n", ans); } return 0; }
#include <bits/stdc++.h> int MOD = int(1e9) + 7; inline int add(int a, int b) { return (a + b >= MOD) ? (a + b - MOD) : (a + b); } inline void inc(int &a, int b) { a = add(a, b); } inline int sub(int a, int b) { return (a - b < 0) ? (a - b + MOD) : (a - b); } inline void dec(int &a, int b) { a = sub(a, b); } inline int mul(int a, int b) { return (a * 1ll * b) % MOD; } using namespace std; const int N = 345678; const long double PI = acosl(-1), EPS = 1e-18; long double ang[2 * N]; long long f(int from, int to) { return 1LL * (to - from) * (to - from - 1) / 2; } int main() { int n, c, d; scanf("%d %d %d", &n, &c, &d); for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); ang[i] = atan2l(y - d, x - c); } sort(ang, ang + n); for (int i = n; i < 2 * n; i++) ang[i] = ang[i - n] + 2 * PI; long long ans = 1LL * n * (n - 1) * (n - 2) / 6; int from = 0, to = 0; for (int i = 0; i < n; i++) { while (ang[from] - ang[i] < PI - EPS) from++; while (ang[to + 1] - ang[i] < PI + EPS) to++; ans += f(from, to + 1) - f(i, to); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 345678; typedef struct P { int x, y; } P; long long operator^(const P &a, const P &b) { return (long long)a.x * b.y - (long long)a.y * b.x; } bool operator<(const P &a, const P &b) { bool apos = a.y > 0 || a.y == 0 && a.x > 0; bool bpos = b.y > 0 || b.y == 0 && b.x > 0; if (apos != bpos) return apos; long long side = a ^ b; if (side != 0) return side > 0; return false; } int n, X0, Y0; P p[2 * MAXN]; void run() { scanf("%d%d%d", &n, &X0, &Y0); for (int i = (0); i < (n); ++i) { scanf("%d%d", &p[i].x, &p[i].y), p[i].x -= X0, p[i].y -= Y0; if (p[i].x == 0 && p[i].y == 0) --i, --n; } sort(p, p + n); for (int i = (0); i < (n); ++i) p[n + i] = p[i]; long long ret = (long long)n * (n - 1) * (n - 2) / 6; for (int at = 0, to = 0, rat = 0, rto = 0; at < n; at = to) { while (to < n && !(p[at] < p[to]) && !(p[to] < p[at])) ++to; if (rat < to) rat = to; while (rat < at + n && (p[at] ^ p[rat]) > 0) ++rat; rto = rat; while (rto < at + n && (p[at] ^ p[rto]) >= 0) ++rto; long long a = to - at, b = rat - to, c = rto - rat; ret -= a * (a - 1) * (a - 2) / 6; ret -= a * (a - 1) / 2 * b; ret -= a * (a - 1) / 2 * c; ret -= a * b * (b - 1) / 2; ret -= a * b * c; } printf("%I64d\n", ret); } int main() { run(); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 2e6; const int INF = 1e9 + 9; const int B = 1e9 + 7; int n, c, d; pair<long long, long long> p[N]; int r[N]; long long dp(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.first * b.first + a.second * b.second; } long long cp(const pair<long long, long long> &a, const pair<long long, long long> &b) { return a.first * b.second - a.second * b.first; } int quad(const pair<long long, long long> &p) { if (p.first <= 0 && p.second < 0) return 1; if (p.first > 0 && p.second <= 0) return 2; if (p.first >= 0 && p.second > 0) return 3; return 4; } bool cmp(const pair<long long, long long> &a, const pair<long long, long long> &b) { if (quad(a) != quad(b)) return quad(a) < quad(b); return cp(a, b) > 0; } ostream &operator<<(ostream &out, const pair<long long, long long> &first) { out << "(" << first.first << " " << first.second << ")"; return out; } int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n >> c >> d; for (int i = int(1); i <= int(n); ++i) { cin >> p[i].first >> p[i].second; p[i].first -= c, p[i].second -= d; } sort(p + 1, p + 1 + n, cmp); if (cp(p[1], p[n]) >= 0) { cout << "0\n"; return 0; } for (int i = int(1); i <= int(n); ++i) { pair<long long, long long> ref(-p[i].first, -p[i].second); if (cmp(p[i], ref)) r[i] = (lower_bound(p + 1, p + 1 + n, ref, cmp) - p) - 1; else r[i] = n; } long long ans = 0, sum = 0; int ptr = 1; for (int i = int(1); i <= int(n); ++i) { long long pairs = r[i] - i; for (; ptr <= r[i]; ++ptr) sum += r[ptr]; sum -= r[i]; ans += sum - (pairs * r[i]); pair<long long, long long> ref(-p[i].first, -p[i].second); if (cmp(p[i], ref)) { int opposite = upper_bound(p + 1, p + 1 + n, ref, cmp) - lower_bound(p + 1, p + 1 + n, ref, cmp); int greaters = r[i] - (upper_bound(p + 1, p + 1 + n, p[i], cmp) - p) + 1; ans -= 1ll * greaters * opposite; } } cerr << ans << "\n"; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)4e5 + 10; const long double PI = acosl(-1); const long double EPS = 1e-18; int n, c, d; long long h[MAXN], f[MAXN], g[MAXN], s[MAXN]; long double P[MAXN]; int main() { scanf("%d%d%d", &n, &c, &d); for (int i = 1; i <= n; ++i) { int x, y; scanf("%d%d", &x, &y); P[i] = atan2l(y - d, x - c); if (P[i] < 0) P[i] += 2 * PI; } sort(P + 1, P + 1 + n); for (int i = 1; i <= n; ++i) { int l = i, r = n; while (l <= r) { int m = (l + r) >> 1; if (abs(P[m] - P[i]) <= EPS) { h[i] = m; l = m + 1; } else r = m - 1; } l = i; r = n; while (l <= r) { int m = (l + r) >> 1; if (P[m] - P[i] < PI - EPS) { f[i] = m; l = m + 1; } else r = m - 1; } l = i; r = n; while (l <= r) { int m = (l + r) >> 1; if (P[m] - P[i] <= PI + EPS) { g[i] = m; l = m + 1; } else r = m - 1; } } for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + f[i] - i + 1; long long ans = 0; for (int i = 1; i <= n; ++i) { long long x = ans; ans += s[f[i]] - s[h[i]] + (h[i] + 1 + f[i]) * (f[i] - h[i]) / 2 - (f[i] - h[i]) * (g[i] + 1); assert(ans >= x); } printf("%I64d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 345679; int r[N], w[N]; vector<double> pos, neg; double p[N]; int main() { int n, c, d, i; scanf("%d %d %d", &n, &c, &d); for (i = 1; i <= n; ++i) { scanf("%d %d", &r[i], &w[i]); r[i] -= c; w[i] -= d; p[i] = ((double)r[i]) / w[i]; } for (i = 1; i <= n; ++i) { if (w[i] > 0) { pos.push_back(p[i]); } if (w[i] < 0) { neg.push_back(p[i]); } } sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end()); long long fi = 0ll, se = 0ll; for (i = 0; i < pos.size(); ++i) { fi += (lower_bound(neg.begin(), neg.end(), pos[i]) - neg.begin()); } for (i = 0; i < neg.size(); ++i) { se += (lower_bound(pos.begin(), pos.end(), neg[i]) - pos.begin()); } long long ans = 0ll; for (i = 1; i <= n; ++i) { if (w[i] > 0) { long long x = neg.end() - upper_bound(neg.begin(), neg.end(), p[i]); x = x * 1ll * (lower_bound(neg.begin(), neg.end(), p[i]) - neg.begin()); ans += x; } if (w[i] < 0) { long long y = pos.end() - upper_bound(pos.begin(), pos.end(), p[i]); y = y * 1ll * (lower_bound(pos.begin(), pos.end(), p[i]) - pos.begin()); ans += y; } if (w[i] == 0) { if (r[i] < 0) { ans += fi; } else { ans += se; } } } printf("%lld", ans); }
#include <bits/stdc++.h> using namespace std; const int N = 700005; const int MOD = 1e9 + 7; const int INF = 0x3f3f3f3f; int n, c, d; long double angle[N]; long double pi = acos((long double)-1); long double eps = 1e-18; long long C(int a) { return (long long)a * (a - 1) / 2; } int main() { scanf("%d%d%d", &n, &c, &d); for (int i = 0; i < n; i++) { int x, y; scanf("%d%d", &x, &y); angle[i] = atan2(y - d, x - c); } sort(angle, angle + n); for (int i = 0; i < n; i++) angle[n + i] = angle[i] + 2 * pi; long long ans = (long long)n * (n - 1) * (n - 2) / 6; int low = 0, high = 0; for (int i = 0; i < n; i++) { while (angle[low] - angle[i] < pi - eps) low++; while (angle[high + 1] - angle[i] < pi + eps) high++; ans -= C(high - i); ans += C(high - low + 1); } printf("%I64d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int MN = 800111; int n; long double a[MN]; long long c2(long long n) { return n * (n - 1) / 2ll; } long long c3(long long n) { return n * (n - 1) * (n - 2) / 6ll; } const long double PI = atan2((long double)0.0, (long double)-1.0); const long double EPS = 1e-18; int main() { ios ::sync_with_stdio(false); int c, d; while (scanf("%d%d%d", &n, &c, &d) == 3) { for (int i = (1), _b = (n); i <= _b; i++) { int x, y; scanf("%d%d", &x, &y); a[i] = atan2(y - d, x - c); } sort(a + 1, a + n + 1); long long res = c3(n); for (int i = (n + 1), _b = (n + n + 3); i <= _b; i++) { a[i] = a[i - n]; a[i] += 2 * PI; } int j = 1, l = 1, r = 1; for (int i = (1), _b = (n); i <= _b; i++) { while (a[j + 1] - a[i] < PI + EPS) ++j; while (a[l] - a[i] < PI - EPS) ++l; while (a[r + 1] - a[i] < PI + EPS) ++r; res -= c2(j - i); res += c2(r - l + 1); } cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); struct node { double x, y; } a[100005], b; double fun(node a) { return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y)); } double fun(node a, node b) { return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y)); } int main() { int i, n; while (~scanf("%d%lf%lf", &n, &b.x, &b.y)) { for (i = 0; i < n; ++i) { scanf("%lf%lf", &a[i].x, &a[i].y); } a[n].x = a[0].x; a[n].y = a[0].y; double r_min = 1e18, r_max = 0; double t_r1, t_r2; for (i = 0; i < n; ++i) { t_r1 = fun(a[i]); t_r2 = fun(a[i + 1]); r_max = max(r_max, t_r1); r_max = max(r_max, t_r2); double t = fun(a[i], a[i + 1]); if (t_r1 * t_r1 + t * t < t_r2 * t_r2) r_min = min(r_min, t_r1); else if (t_r2 * t_r2 + t * t < t_r1 * t_r1) r_min = min(r_min, t_r2); else { double p = (t + t_r1 + t_r2) / 2; double s = sqrt(p * (p - t) * (p - t_r1) * (p - t_r2)); double r = 2 * s / t; r_min = min(r_min, r); } } printf("%.12f\n", pi * (r_max * r_max - r_min * r_min)); } return 0; }
#include <bits/stdc++.h> using namespace std; void read_file(bool outToFile = true) {} struct point; struct vec; struct line; struct circle; struct triangle; double to_rad(double theta); double to_deg(double theta); double dist(point p, point q); point middle(point p, point q); point translate(point p, vec u); double norm_sq(vec u); double dot(vec u, vec v); double cross(vec u, vec v); bool are_parallel(line l, line d); bool are_same(line l, line d); double dist_to_line(point p, point a, point b); bool ccw(point p, point q, point r); bool collinear(point p, point q, point r); double angle(point a, point o, point b); point rotate(point p, double theta, point q); point intersection(line l, line d); bool check_range(double v, double l1, double r1, double l2, double r2); point segment_intersection(point p, point q, point r, point t); bool point_on_ray(point p, point a, point b); bool point_on_segment(point p, point a, point b); point projection(point p, point a, point b); double dist_to_segment(point p, point a, point b); point reflection(point p, point a, point b); line perpendicular(point p, point a, point b); line bisector(point a, point o, point b); circle find_circle(point p, point q, double r); circle in_circle(triangle t); circle circum_circle(triangle t); double perimeter(vector<point> P); double area(vector<point> P); bool is_convex(vector<point> P); bool is_in(point p, vector<point> P); vector<point> cut(vector<point> P, point a, point b); bool ch_cmp(point a, point b); vector<point> convex_hull(vector<point> P); void print(vector<point> P); struct point { double x, y; point(double nx = 0, double ny = 0) { x = nx, y = ny; } bool operator==(point p) { return fabs(x - p.x) <= (1e-9) && fabs(y - p.y) <= (1e-9); } bool operator!=(point p) { return fabs(x - p.x) > (1e-9) || fabs(y - p.y) > (1e-9); } bool operator<(point p) { if (fabs(x - p.x) > (1e-9)) return x < p.x - (1e-9); return y < p.y - (1e-9); } friend istream &operator>>(istream &is, point &p) { return is >> p.x >> p.y; } friend ostream &operator<<(ostream &os, point &p) { return os << p.x << ' ' << p.y; } }; struct vec { double x, y; vec(double nx = 0, double ny = 0) { x = nx, y = ny; } vec(point p, point q) { x = q.x - p.x, y = q.y - p.y; } vec operator+(vec u) { return vec(x + u.x, y + u.y); } vec operator-(vec u) { return vec(x - u.x, y - u.y); } vec operator*(double k) { return vec(k * x, k * y); } friend istream &operator>>(istream &is, vec &u) { return is >> u.x >> u.y; } friend ostream &operator<<(ostream &os, vec &u) { return os << u.x << ' ' << u.y; } }; struct line { double a, b, c; line(double na = 0, double nb = 0, double nc = 0) { a = na, b = nb, c = nc; } line(point p, point q) { double dx = q.x - p.x; double dy = q.y - p.y; if (fabs(dx) <= (1e-9)) { a = 1, b = 0, c = -p.x; return; } a = -dy / dx; b = 1.0; c = dy / dx * p.x - p.y; } line(point p, double m) { a = -m; b = 1.0; c = -(a * p.x + p.y); } pair<point, point> to_points() { point p, q; if (fabs(b) <= (1e-9)) p.x = -c / a, q.x = p.x, p.y = 0, q.y = 1; else p.x = 0, q.x = 1, p.y = -(a * p.x + c), q.y = -(a * q.x + c); return make_pair(p, q); } }; struct circle { double x, y, r; circle(point c = point(0, 0), double nr = 0) { x = c.x, y = c.y, r = nr; } int is_in(point p) { double dx = p.x - x, dy = p.y - y; double d = dx * dx + dy * dy, R = r * r; return (d < R - (1e-9)) ? 0 : (fabs(d - R) <= (1e-9)) ? 1 : 2; } double perimeter(double theta = 360) { theta = to_rad(theta); return theta * r; } double area(double theta = 360) { theta = to_rad(theta); return theta * r * r / 2; } }; struct triangle { point A, B, C; double a, b, c; triangle(double na = 0, double nb = 0, double nc = 0) { a = na, b = nb, c = nc; } triangle(point nA, point nB, point nC) { A = nA, B = nB, C = nC; c = dist(A, B), a = dist(B, C), b = dist(C, A); } bool is_triangle() { return a + b > c + (1e-9) && b + c > a + (1e-9) && c + a > b + (1e-9); } double perimeter() { return a + b + c; } double area() { double s = perimeter() / 2; return sqrt(s * (s - a) * (s - b) * (s - c)); } }; double to_rad(double theta) { return theta * acos(-1.0) / 180; } double to_deg(double theta) { return theta * 180 / acos(-1.0); } double dist(point p, point q) { return hypot(p.x - q.x, p.y - q.y); } point middle(point p, point q) { return point((p.x + q.x) / 2, (p.y + q.y) / 2); } point translate(point p, vec u) { return point(p.x + u.x, p.y + u.y); } double norm_sq(vec u) { return u.x * u.x + u.y * u.y; } double dot(vec u, vec v) { return u.x * v.x + u.y * v.y; } double cross(vec u, vec v) { return u.x * v.y - u.y * v.x; } bool are_parallel(line l, line d) { return fabs(l.a - d.a) <= (1e-9) && fabs(l.b - l.b) <= (1e-9); } bool are_same(line l, line d) { return are_parallel(l, d) && fabs(l.c - d.c) <= (1e-9); } double dist_to_line(point p, point a, point b) { return dist(p, projection(p, a, b)); } bool ccw(point p, point q, point r) { return cross(vec(p, q), vec(p, r)) > 0 + (1e-9); } bool collinear(point p, point q, point r) { return fabs(cross(vec(p, q), vec(p, r))) <= (1e-9); } double angle(point a, point o, point b) { vec oa = vec(o, a), ob = vec(o, b); return acos(dot(oa, ob) / sqrt(norm_sq(oa) * norm_sq(ob))); } point rotate(point p, double theta, point q = point(0, 0)) { vec oq = vec(point(0, 0), q); p = translate(p, oq * -1); theta = to_rad(theta); double x = p.x * cos(theta) - p.y * sin(theta); double y = p.x * sin(theta) + p.y * cos(theta); p = point(x, y); p = translate(p, oq); return p; } point intersection(line l, line d) { if (are_parallel(l, d)) return point((1000000000), (1000000000)); point p; p.x = (d.b * l.c - l.b * d.c) / (d.a * l.b - l.a * d.b); if (fabs(l.b) > (1e-9)) p.y = -(l.a * p.x + l.c); else p.y = -(d.a * p.x + d.c); return p; } bool check_range(double v, double l, double r) { if (l > r + (1e-9)) swap(l, r); if (fabs(r - l) <= (1e-9)) return fabs(v - l) <= (1e-9); return l < v - (1e-9) && v < r - (1e-9); return l <= v + (1e-9) && v <= r + (1e-9); } point segment_intersection(point p, point q, point r, point t) { point c = intersection(line(p, q), line(r, t)); if (point_on_segment(c, p, q) && point_on_segment(c, r, t)) return c; return point((1000000000), (1000000000)); } bool point_on_ray(point p, point a, point b) { vec ap = vec(a, p), ab = vec(a, b); return collinear(p, a, b) && dot(ap, ab) >= -(1e-9); } bool point_on_segment(point p, point a, point b) { return point_on_ray(p, a, b) && point_on_ray(p, b, a); } point projection(point p, point a, point b) { vec ap = vec(a, p), ab = vec(a, b); double u = dot(ap, ab) / norm_sq(ab); return translate(a, ab * u); } double dist_to_segment(point p, point a, point b) { vec ap = vec(a, p), ab = vec(a, b); double u = dot(ap, ab) / norm_sq(ab); if (u < 0 - (1e-9)) return dist(p, a); if (u > 1 + (1e-9)) return dist(p, b); return dist_to_line(p, a, b); } point reflection(point p, point a, point b) { point c = projection(p, a, b); vec pc = vec(p, c); return translate(p, pc * 2); } line perpendicular(point p, point a, point b) { if (!collinear(p, a, b)) return line(p, projection(p, a, b)); line l = line(a, b); if (fabs(l.b) <= (1e-9)) return line(p, point(p.x + 1, p.y)); if (fabs(l.a) <= (1e-9)) return line(p, point(p.x, p.y + 1)); return line(p, 1 / l.a); } line bisector(point a, point o, point b) { double ratio = dist(o, a) / dist(o, b); ratio /= ratio + 1; vec ab = vec(a, b); point c = translate(a, ab * ratio); return line(o, c); } circle find_circle(point p, point q, double r) { point m = middle(p, q); vec mp = vec(m, p); double mc = r * r - norm_sq(mp); if (mc < 0 - (1e-9)) return circle(); mc = sqrt(mc); double u = mc / dist(m, p); point c = translate(m, mp * u); c = rotate(c, 90, m); return circle(c, r); } circle in_circle(triangle t) { double r = 2 * t.area() / t.perimeter(); if (fabs(r) <= (1e-9)) return circle(); line l = bisector(t.B, t.A, t.C); line d = bisector(t.C, t.B, t.A); point c = intersection(l, d); return circle(c, r); } circle circum_circle(triangle t) { double r = (t.a * t.b * t.c) / (4 * t.area()); if (fabs(r) <= (1e-9)) return circle(); line l = perpendicular(middle(t.A, t.B), t.A, t.B); line d = perpendicular(middle(t.A, t.C), t.A, t.C); point c = intersection(l, d); return circle(c, r); } point pivot; double perimeter(vector<point> P) { int n = P.size(); double ret = 0; for (int i = 0; i < n - 1; i++) ret += dist(P[i], P[i + 1]); return ret; } double area(vector<point> P) { int n = P.size(); double ret = 0; double x1, x2, y1, y2; for (int i = 0; i < n - 1; i++) { x1 = P[i].x, x2 = P[i + 1].x; y1 = P[i].y, y2 = P[i + 1].y; ret += x1 * y2 - x2 * y1; } ret /= 2, ret = fabs(ret); return ret; } bool is_convex(vector<point> P) { int n = P.size(); if (n <= 3) return false; bool turn = ccw(P[0], P[1], P[2]); for (int i = 1; i < n - 1; i++) if (ccw(P[i], P[i + 1], P[i + 2 != n ? i + 2 : 1]) != turn) return false; return true; } bool is_in(point p, vector<point> P) { int n = P.size(); double sum = 0; for (int i = 0; i < n - 1; i++) if (ccw(P[i], p, P[i + 1])) sum += angle(P[i], p, P[i + 1]); else sum -= angle(P[i], p, P[i + 1]); sum = fabs(sum); return fabs(sum - 2 * acos(-1.0)) <= (1e-9); } vector<point> cut(vector<point> P, point a, point b) { int n = P.size(); vector<point> ret; for (int i = 0; i < n; i++) { double left1 = cross(vec(a, b), vec(a, P[i])); double left2 = (i != n - 1) ? cross(vec(a, b), vec(a, P[i + 1])) : 0; if (left1 >= -(1e-9)) ret.push_back(P[i]); if (left1 * left2 < -(1e-9)) ret.push_back(intersection(line(a, b), line(P[i], P[i + 1]))); } if (!ret.empty() && ret.front() != ret.back()) ret.push_back(ret.front()); return ret; } bool ch_cmp(point a, point b) { if (collinear(pivot, a, b)) return dist(pivot, a) < dist(pivot, b) - (1e-9); double dx1 = a.x - pivot.x, dy1 = a.y - pivot.y; double dx2 = b.x - pivot.x, dy2 = b.y - pivot.y; return atan2(dy1, dx1) < atan2(dy2, dx2) - (1e-9); } vector<point> convex_hull(vector<point> P) { int n = P.size(); if (n <= 3) { if (n != 0 && P[0] != P[n - 1]) P.push_back(P[0]); return P; } int idx = 0; for (int i = 1; i < n; i++) if (P[idx].y > P[i].y + (1e-9) || (fabs(P[idx].y - P[i].y) <= (1e-9) && P[idx].x < P[i].x - (1e-9))) idx = i; swap(P[0], P[idx]); pivot = P[0]; sort(P.begin() + 1, P.end(), ch_cmp); vector<point> ch; ch.push_back(P[n - 1]), ch.push_back(P[0]), ch.push_back(P[1]); int i = 2; while (i < n) { int j = ch.size() - 1; if (ccw(ch[j - 1], ch[j], P[i])) ch.push_back(P[i]), i++; else ch.pop_back(); } return ch; } void print(vector<point> P) { int n = P.size(); cout << '\n'; for (int i = 0; i < n; i++) cout << P[i] << '\n'; cout << '\n'; } int n; point A[100000 + 9]; point O; double r, R; void check(double d) { if (d < r - (1e-9)) r = d; if (d > R + (1e-9)) R = d; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); read_file(); while (cin >> n) { cin >> O; for (int i = 0; i < n; i++) cin >> A[i]; n++; A[n - 1] = A[0]; r = (1000000000), R = -(1000000000); for (int i = 0; i < n - 1; i++) { double d = dist(O, A[i]); check(d); d = dist_to_segment(O, A[i], A[i + 1]); check(d); } double ans = acos(-1.0) * (R * R - r * r); cout << setprecision(25) << ans << '\n'; } }
#include <bits/stdc++.h> using namespace std; int sign(double x, double eps = 1e-9) { return x < -eps ? -1 : x > eps; } struct point { double x, y; point(double x = 0, double y = 0) : x(x), y(y) {} double det(point p) { return x * p.y - y * p.x; } double dis2(point p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } void show() { cout << x << " " << y << endl; } }; 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 k) { return point(a.x * k, a.y * k); } point operator/(point a, double k) { return point(a.x / k, a.y / k); } struct line { point a, b; line(point a = point(0, 0), point b = point(0, 0)) : a(a), b(b) {} point intersect(line l) { double s1 = (b - a).det(l.a - a); double s2 = (b - a).det(l.b - a); return (l.a * s2 - l.b * s1) / (s2 - s1); } line vertical(point p) { return line(p, p + point(b.y - a.y, a.x - b.x)); } int include(point p) { return sign((b.x - p.x) * (p.x - a.x)) >= 0 && sign((b.y - p.y) * (p.y - a.y)) >= 0; } }; int main() { int n; double r = 1e14, R = 0; point p, pre, now, first; cin >> n >> p.x >> p.y >> first.x >> first.y; now = first; for (int i = 0; i < n; i++) { if (i < n - 1) { pre = now; cin >> now.x >> now.y; } else pre = first; r = min(r, p.dis2(now)); r = min(r, p.dis2(pre)); line temp = line(now, pre), vtemp = temp.vertical(p); point inter = temp.intersect(vtemp); if (temp.include(inter)) r = min(r, p.dis2(inter)); R = max(R, p.dis2(now)); R = max(R, p.dis2(pre)); } printf("%.18f\n", 3.14159265358979323846 * (R - r)); }
#include <bits/stdc++.h> using namespace std; inline namespace Infinity { const char CR = '\n'; inline void write(const int n) { printf("%d", n); } inline void write(const unsigned n) { printf("%u", n); } inline void write(const long long n) { cout << n; } inline void write(const unsigned long long n) { cout << n; } inline void writef(const double a, const int n = 15) { printf("%.*f", n, a); } inline void writef(const long double a, const int n = 18) { cout << setprecision(n) << fixed << a; } inline void write(const char c) { printf("%c", c); } inline void write(const char s[] = "") { printf("%s", s); } inline void write(const string &s) { cout << s; } inline void write(const pair<int, int> &p) { printf("%d %d", p.first, p.second); } template <class T> inline void write(const T a) { for (auto i : a) write(i); } inline void writeln() { write(CR); } template <typename T> inline void writeln(const T &a) { write(a); write(CR); } inline void writefln(const double a, int n) { printf("%.*f", n, a); write(CR); } inline void writefln(const long double a, int n = 18) { cout << setprecision(n) << fixed << a << endl; } inline void writesln(const int *a, const int l, const int r) { for (int i = l; i <= r; i++) printf("%d ", a[i]); writeln(CR); } template <class T> inline void writelns(const T a) { for (__typeof a.begin() i = a.begin(); i != a.end(); i++) writeln(*i); } template <typename T, typename... types> inline void write(const T &a, const types &...args) { write(a); write(args...); } template <typename... types> inline void writeln(const types &...args) { write(args...); write(CR); } inline void writelnYN(bool b) { writeln(b ? "YES" : "NO"); } inline void writelnyn(bool b) { writeln(b ? "Yes" : "No"); } inline int read(int &n) { return scanf("%d", &n); } inline int read(long long &n) { return cin >> n ? 1 : -1; } template <typename T, typename... types> inline int read(T &n, types &...args) { read(n); return read(args...); } inline char getcc() { char c; do c = getchar(); while (c == ' ' || c == '\n'); return c; } inline int getint() { int n; read(n); return n; } inline long long getll() { long long n; read(n); return n; } inline double getdouble() { double n; scanf("%lf", &n); return n; } inline vector<int> getints(int n) { vector<int> v(n); for (int i = 0; i < n; i++) v[i] = getint(); return v; } inline vector<pair<int, int>> getpairs(int n) { vector<pair<int, int>> v(n); for (int i = 0; i < n; i++) { int a = getint(), b = getint(); v[i] = pair<int, int>(a, b); } return v; } inline void read(string &str, const unsigned size) { char s[size]; scanf("%s", s); str = string(s); } inline string getstr(const unsigned size = 1048576) { string s; read(s, size + 1); return s; } inline string getln(const unsigned size = 1048576) { char s[size + 1]; scanf("%[^\n]", s); return string(s); } } // namespace Infinity inline namespace Infinity { inline namespace Geometry { class Point { public: Point(long double x = 0, long double y = 0) : x(x), y(y) {} Point(const pair<int, int> &p) : x(p.first), y(p.second) {} long double x, y; }; class Line { public: Line(long double a, long double b, long double c) : a(a), b(b), c(c) {} Line(Point p1, Point p2) { assert(p1.x != p2.x || p1.y != p2.y); a = p2.y - p1.y; b = p1.x - p2.x; c = p1.y * (p2.x - p1.x) - p1.x * (p2.y - p1.y); } long double a, b, c; }; const long double pi = acosl(-1); const long double eps = 1e-15l; long double sq(long double a) { return a * a; } long double dist(Point a, Point b) { return sqrtl(sq(a.x - b.x) + sq(a.y - b.y)); } bool parallel(Line l1, Line l2) { return l1.a * l2.b - l1.b * l2.a == 0; } Point intersection(Line l1, Line l2) { assert(parallel(l1, l2) == false); return Point((l1.b * l2.c - l2.b * l1.c) / (l1.a * l2.b - l2.a * l1.b), (l1.a * l2.c - l2.a * l1.c) / (l2.a * l1.b - l1.a * l2.b)); } Point footPoint(Point pt, Line ln) { Line pl(ln.b, -ln.a, pt.y * ln.a - pt.x * ln.b); return intersection(ln, pl); } long double dist(Point pt, Line ln) { return fabsl(ln.a * pt.x + ln.b * pt.y + ln.c) / sqrtl(sq(ln.a) + sq(ln.b)); } } // namespace Geometry } // namespace Infinity int main() { int n = getint(); long double x = getint(); long double y = getint(); vector<pair<int, int>> a = getpairs(n); long double maxr = 0; long double minr = LLONG_MAX; for (unsigned i = 0; i < a.size(); i++) maxr = max(maxr, dist(Point(a[i].first, a[i].second), Point(x, y))); for (unsigned i = 0; i < a.size(); i++) { Point p1(a[i].first, a[i].second); Point p2(a[(i + 1) % a.size()].first, a[(i + 1) % a.size()].second); Point fp = footPoint(Point(x, y), Line(p1, p2)); if (dist(p1, fp) + dist(fp, p2) <= dist(p1, p2) + eps) minr = min(minr, dist(Point(x, y), Line(p1, p2))); minr = min(minr, dist(p1, Point(x, y))); minr = min(minr, dist(p2, Point(x, y))); } writefln(pi * (maxr * maxr - minr * minr)); return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const double pi = acos(-1.0); double calc(double x, double y, double a, double b) { return sqrt((x - a) * (x - a) + (y - b) * (y - b)); } double calc2(long long x1, long long y1, long long x2, long long y2, long long x0, long long y0) { long long vx = x2 - x1; long long vy = y2 - y1; long long det = vx * vx + vy * vy; double t = 1.0 * (vx * (x0 - x1) + vy * (y0 - y1)) / det; double res = 1e18; if (0.0 <= t && t <= 1.0) { double xc = x1 + t * (x2 - x1); double yc = y1 + t * (y2 - y1); res = calc(xc, yc, x0, y0); } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(12); cout << fixed; int n, xo, yo; scanf("%d %d %d", &n, &xo, &yo); vector<int> x(n), y(n); for (int i = 0; i < n; ++i) scanf("%d %d", &x[i], &y[i]); double rmax = -1.0; double rmin = 1.0e18; long long xp, yp; for (int i = 0; i < n; ++i) { double r = calc(x[i], y[i], xo, yo); rmax = max(rmax, r); rmin = min(rmin, r); rmin = min(rmin, calc2(x[i], y[i], x[(i + 1) % n], y[(i + 1) % n], xo, yo)); } double res = 0; res += rmax * rmax * pi; res -= rmin * rmin * pi; printf("%.11f", res); return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = int(1e5 + 5); const double PI = acos(-1); int n; struct Point { int x, y; double d; Point() {} Point(int x, int y); } p, a[MAXN]; double sqr(double x) { return x * x; } double Dis(Point A, Point B) { return sqrt(sqr(A.x - B.x) + sqr(A.y - B.y)); } long long Det(Point A, Point B, Point C) { return 1ll * A.x * B.y + 1ll * B.x * C.y + 1ll * C.x * A.y - 1ll * A.y * B.x - 1ll * B.y * C.x - 1ll * C.y * A.x; } Point::Point(int x, int y) : x(x), y(y) { d = Dis(*this, p); } int main() { cin >> n; int x, y; cin >> p.x >> p.y; for (int i = 0; i < n; i++) { cin >> x >> y; a[i] = Point(x, y); } double l, _min = 1e18, _max = 0; for (int i = 0; i < n; i++) { _min = min(_min, a[i].d); _max = max(_max, a[i].d); l = Dis(a[i], a[(i + 1) % n]); if (sqr(l) + sqr(a[i].d) > sqr(a[(i + 1) % n].d) && sqr(l) + sqr(a[(i + 1) % n].d) > sqr(a[i].d)) { _min = min(_min, abs((double)Det(a[i], p, a[(i + 1) % n])) / l); } } printf("%.9f\n", PI * (sqr(_max) - sqr(_min))); return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100005; const double ERROR = 1e-12; const double pi = acos(-1); bool equals(double a, double b) { return fabs(a - b) < ERROR; } struct Point { double x, y; Point() {} Point(double _x, double _y) { x = _x, y = _y; } double operator-(const Point& p) { double xx = x - p.x, yy = y - p.y; return sqrt(xx * xx + yy * yy); } }; struct Segment { Point a, b; Segment() {} Segment(Point _a, Point _b) { a = _a, b = _b; } }; struct Line { double a, b, c; Line() {} Line(Point p1, Point p2) { a = p1.y - p2.y; b = p2.x - p1.x; c = p1.x * p2.y - p1.y * p2.x; } bool intersects(Point& p, Line line) { double determinant = a * line.b - b * line.a; if (equals(determinant, 0)) return false; p.x = (b * line.c - c * line.b) / determinant; p.y = (c * line.a - a * line.c) / determinant; return true; } Line perpendicular(Point p) { Line res; res.a = b, res.b = -a; res.c = -res.a * p.x - res.b * p.y; return res; } double distance(Point p) { return fabs(a * p.x + b * p.y + c) / sqrt(a * a + b * b); } }; double distance(Point p, Segment s) { Line cur = Line(s.a, s.b), perp; Point cross; perp = cur.perpendicular(p); if (cur.intersects(cross, perp)) { if (equals((cross - s.a) + (cross - s.b), s.a - s.b)) { return cur.distance(p); } } return min(s.a - p, s.b - p); } Point points[N]; int main() { ios ::sync_with_stdio(false); int n; cin >> n; Point O; double mind = 1e18, maxd = -mind; cin >> O.x >> O.y; for (int i = 0; i < n; i++) { cin >> points[i].x >> points[i].y; } points[n] = points[0]; for (int i = 0; i < n; i++) { maxd = max(O - points[i], maxd); mind = min(distance(O, Segment(points[i], points[i + 1])), mind); } cout << fixed << setprecision(12) << pi * (maxd * maxd - mind * mind) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; } p[100010], a; double dis(Point a, Point b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } double disans(Point a, Point p, Point q) { Point h; 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; h.x = p.x + (q.x - p.x) * r; h.y = p.y + (q.y - p.y) * r; return dis(h, a); } double maxf = -1e18, minf = 1e18; int main() { int n, i; scanf("%d %lf %lf", &n, &a.x, &a.y); for (i = 1; i <= n; i++) { scanf("%lf%lf", &p[i].x, &p[i].y); double r = dis(p[i], a); maxf = max(maxf, r); minf = min(minf, r); } for (i = 1; i <= n; i++) { int j = i + 1; if (j > n) j -= n; minf = min(minf, disans(a, p[i], p[j])); } printf("%.20lf", (maxf - minf) * 3.14159265358979323846); return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point() {} Point(const double &x, const double &y) : x(x), y(y) {} void Read() { scanf("%lf%lf", &x, &y); } double sqrlen() { return x * x + y * y; } double len() { return sqrt(sqrlen()); } } p, a[111111]; Point operator-(const Point &a, const Point &b) { return Point(a.x - b.x, a.y - b.y); } double minnn(Point p1, Point p2, Point p) { double ans = 0; double a, b, c; a = (p1 - p2).len(); b = (p1 - p).len(); c = (p2 - p).len(); if (c + b == a) { ans = 0; return ans; } if (a <= 0.00001) { ans = b; return ans; } if (c * c >= a * a + b * b) { ans = b; return ans; } if (b * b >= a * a + c * c) { ans = c; return ans; } double p0 = (a + b + c) / 2; double s = sqrt(p0 * (p0 - a) * (p0 - b) * (p0 - c)); ans = 2 * s / a; return ans; } int main() { int n; scanf("%d", &n); p.Read(); double minn, maxn; for (int i = 1; i <= n; i++) { a[i].Read(); if (i == 1) minn = maxn = (a[i] - p).sqrlen(); else { double c = (a[i] - p).sqrlen(); if (c > maxn) maxn = c; if (c < minn) minn = c; c = minnn(a[i], a[i - 1], p); c *= c; if (c < minn) minn = c; } } double c = minnn(a[1], a[n], p); c *= c; if (c < minn) minn = c; printf("%.8f\n", acos(-1.0) * (maxn - minn)); }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; pair<double, double> operator-(const pair<double, double>& lhs) { return {-lhs.first, -lhs.second}; } pair<double, double> operator+(const pair<double, double>& lhs, const pair<double, double>& rhs) { return {lhs.first + rhs.first, lhs.second + rhs.second}; } pair<double, double> operator-(const pair<double, double>& lhs, const pair<double, double>& rhs) { return {lhs.first - rhs.first, lhs.second - rhs.second}; } pair<double, double> operator/(const pair<double, double>& lhs, const double& rhs) { return {lhs.first / rhs, lhs.second / rhs}; } pair<double, double> operator*(const pair<double, double>& lhs, const double& rhs) { return {lhs.first * rhs, lhs.second * rhs}; } double operator*(const pair<double, double>& lhs, const pair<double, double>& rhs) { return lhs.first * rhs.first + lhs.second * rhs.second; } double dist(const pair<double, double>& p) { return sqrt(p.first * p.first + p.second * p.second); } istream& operator>>(istream& i, pair<double, double>& p) { i >> p.first >> p.second; return i; } ostream& operator<<(ostream& o, const pair<double, double>& p) { o << p.first << ' ' << p.second; return o; } double dist_to_lineseg(const pair<double, double>& p0, const pair<double, double>& p1, const pair<double, double>& P) { pair<double, double> u = p1 - p0; pair<double, double> v = P - p0; double t = (v * u) / (u * u); if (t <= 0) return dist(P - p0); else if (t >= 1) return dist(P - p1); else return dist(P - (p0 + u * t)); } int main() { cout.precision(9); int n; cin >> n; pair<double, double> p, a[n], c; cin >> p; double md, xd, td; int best0, best1; c = {0, 0}; for (int i = 0; i < n; i++) { cin >> a[i]; a[i] = a[i] - p; td = dist(a[i]); if (i == 0) { xd = td; } else { xd = max(xd, td); } } md = xd; for (int i = 0; i < n; i++) md = min(md, dist_to_lineseg(a[i], a[(i + 1) % n], {0, 0})); cout << fixed << PI * xd * xd - PI * md * md << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct Point { double x, y; Point(double X = 0.0, double Y = 0.0) { x = X; y = Y; } Point operator+(const Point &A) const { return Point(A.x + x, A.y + y); } Point operator-(const Point &A) const { return Point(x - A.x, y - A.y); } double operator*(const Point &A) const { return x * A.x + y * A.y; } double operator^(const Point &A) const { return x * A.y - y * A.x; } bool operator==(const Point &A) const { return (x == A.x && y == A.y); } bool operator<(const Point &A) const { if (x == A.x) return y < A.y; return x < A.x; } }; double norma(const Point &A) { return sqrt(A * A); } double dist(const Point &A, const Point &B) { return norma(A - B); } bool f(Point P, Point A, Point B) { double a = dist(P, A); double b = dist(P, B); double c = dist(A, B); return (((a * a + c * c) >= b * b) && ((b * b + c * c) >= a * a)); } double dist_Point_to_Line(Point P, Point P0, Point P1) { Point v = P1 - P0; Point w = P - P0; double c1 = (w * v); double c2 = (v * v); double b = c1 / c2; Point Pb = P0 + Point(b * v.x, b * v.y); return dist(P, Pb); } int main() { int n; Point P, C; double a = 0x3f3f3f3f * 1.0, b = 0.0, x, ans; scanf("%d", &n); vector<Point> v(n); cin >> P.x >> P.y; for (int i = 0; i < n; i++) cin >> v[i].x >> v[i].y; for (int i = 0; i < n; i++) { x = dist(P, v[i]); a = min(a, x); b = max(b, x); if (f(P, v[i], v[(i + 1) % n])) { a = min(a, dist_Point_to_Line(P, v[i], v[(i + 1) % n])); } } ans = (b * b - a * a) * acos(-1.0); printf("%.8lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; 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 (d < r && is_inside(p, v[i], v[i + 1])) r = d; } cout << setprecision(13) << fixed << PI * (rr * rr - r * r) << "\n\n"; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; struct Point { long long x, y; void operator-=(Point b) { this->x -= b.x; this->y -= b.y; } } node[N], p; double len(Point a, Point b) { double r = (a.x - b.x) * (a.x) + (a.y - b.y) * a.y; double d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); if (r <= 0) return a.x * a.x + a.y * a.y; else if (r >= d) return b.x * b.x + b.y * b.y; r /= d; double x = a.x + (b.x - a.x) * r, y = a.y + (b.y - a.y) * r; return x * x + y * y; } int main() { int n; double r1, r2, t; cin >> n >> p.x >> p.y; r2 = 0; for (int i = 0; i < n; i++) { cin >> node[i].x >> node[i].y; node[i] -= p; t = node[i].x * node[i].x + node[i].y * node[i].y; if (r2 < t) r2 = t; } r1 = 9999999999999; node[n] = node[0]; for (int i = 0; i < n; i++) r1 = min(r1, len(node[i + 1], node[i])); cout.setf(ios::fixed); cout << setprecision(18) << acos(-1) * (r2 - r1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") int _MAX(int a, int b) { return a > b ? a : b; } int _MIN(int a, int b) { return a > b ? b : a; } int Scan() { int res = 0, flag = 0; char ch; if ((ch = getchar()) == '-') flag = 1; else if (ch >= '0' && ch <= '9') res = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + (ch - '0'); return flag ? -res : res; } void Out(int a) { if (a < 0) { putchar('-'); a = -a; } if (a >= 10) Out(a / 10); putchar(a % 10 + '0'); } long long a[100005][2]; long long dis(long long x1, long long y1, long long x2, long long y2) { return (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); } int main() { long long n, px, py, ma = 0; double mi = 1e16; scanf("%lld%lld%lld", &n, &px, &py); for (int i = 1; i <= n; ++i) { scanf("%lld%lld", &a[i][0], &a[i][1]); long long d = dis(a[i][0], a[i][1], px, py); mi = min(mi, (double)d); ma = max(ma, d); } a[n + 1][0] = a[1][0], a[n + 1][1] = a[1][1]; for (int i = 1; i <= n; ++i) { long long A2 = dis(px, py, a[i][0], a[i][1]); long long B2 = dis(px, py, a[i + 1][0], a[i + 1][1]); long long C2 = dis(a[i][0], a[i][1], a[i + 1][0], a[i + 1][1]); double A = sqrt(A2), B = sqrt(B2), C = sqrt(C2); if (C2 + B2 > A2 && C2 + A2 > B2) { double P = (A + B + C) / 2; double S = sqrt(P * (P - A) * (P - B) * (P - C)); double H = S / C * 2; mi = min(mi, H * H); } } printf("%.10lf\n", acos(-1.0) * (ma - mi)); return 0; }
#include <bits/stdc++.h> unsigned char has_obtuse(double x1, double y1, double x2, double y2, double x3, double y3) { double side1, side2, side3; side1 = (x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3); side2 = (x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3); side3 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); return (side1 > side2 + side3 || side2 > side1 + side3); } double distance(int x1, int y1, int x2, int y2, int px, int py) { if (has_obtuse(x1, y1, x2, y2, px, py)) { double d1 = sqrt((double)(x1 - px) * (x1 - px) + (double)(y1 - py) * (y1 - py)); double d2 = sqrt((double)(x2 - px) * (x2 - px) + (double)(y2 - py) * (y2 - py)); return d1 < d2 ? d1 : d2; } double a, b, c; if (x1 == x2) { a = 1; b = 0; c = -x1; } else { a = y2 - y1; b = x1 - x2; c = -(y1 * b + x1 * a); } return fabs(a * px + b * py + c) / sqrt(a * a + b * b); } int main() { int n, px, py; int x1, y1, x2, y2, x0 = 0x7fffffff, y0 = 0x7fffffff; double dist, maxdist = -1, mindist = 999999999; scanf("%d%d%d", &n, &px, &py); do { x1 = x2; y1 = y2; scanf("%d%d", &x2, &y2); if (x0 == 0x7fffffff) { x0 = x2; y0 = y2; } else { dist = distance(x1, y1, x2, y2, px, py); if (dist > maxdist) maxdist = dist; if (dist < mindist) mindist = dist; } dist = sqrt((double)(x2 - px) * (x2 - px) + (double)(y2 - py) * (y2 - py)); if (dist > maxdist) maxdist = dist; if (dist < mindist) mindist = dist; } while (--n); dist = distance(x2, y2, x0, y0, px, py); if (dist > maxdist) maxdist = dist; if (dist < mindist) mindist = dist; printf("%.12lf\n", (double)(maxdist * maxdist - mindist * mindist) * M_PI); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); int n, x0z, y0z; double xx[100001], yy[100001]; double rmax, rmin; double dist(double x, double y) { return sqrt(x * x + y * y); } double cal(int X1, int Y1, int X2, int Y2) { if (Y1 == Y2) { if (X1 > 0 && X2 > 0 || X2 < 0 && X1 < 0) return 1e15; return abs(Y1); } if (X1 == X2) { if (Y1 > 0 && Y2 > 0 || Y2 < 0 && Y1 < 0) return 1e15; return abs(X1); } double k = (Y1 - Y2) * 1.0 / (X1 - X2); double b = Y1 - k * X1; double x = -b / (k + 1.0 / k); if (x < X1 && x < X2) return 1e15; if (x > X1 && x > X2) return 1e15; return dist(x, k * x + b); } int main() { scanf("%d%d%d", &n, &x0z, &y0z); rmax = 0; rmin = 1e15; for (int i = 1; i <= n; i++) { int x, y; scanf("%d%d", &x, &y); xx[i] = x; yy[i] = y; double nowdist = dist(x - x0z, y - y0z); rmax = max(rmax, nowdist); rmin = min(rmin, nowdist); } for (int i = 1; i <= n; i++) { int now = (i - 2 + n) % n + 1; double nowans = cal(xx[now] - x0z, yy[now] - y0z, xx[i] - x0z, yy[i] - y0z); rmin = min(rmin, nowans); } double ans = rmax * rmax * pi - rmin * rmin * pi; printf("%.18lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; int _x, _y, x[100010], y[100010]; int n; double dis(double _x1, double _y1, double _x2, double _y2) { double dx = _x1 - _x2, dy = _y1 - _y2; return sqrt(dx * dx + dy * dy); } int main() { while (~scanf("%d", &n)) { scanf("%d", &_x); scanf("%d", &_y); double mins = 1e15, maxs = -1; for (int i = 1; i <= n; i++) { scanf("%d", &x[i]); scanf("%d", &y[i]); double dist = dis(x[i], y[i], _x, _y); mins = min(mins, dist); maxs = max(maxs, dist); } x[n + 1] = x[1], y[n + 1] = y[1]; for (int i = 1; i <= n; i++) { double k = 0, px = 0, py = 0; if (x[i + 1] == x[i]) px = x[i], py = _y; else if (y[i + 1] == y[i]) px = _x, py = y[i]; else { k = ((double)y[i + 1] - y[i]) / (x[i + 1] - x[i]); double k1 = -1; k1 /= k; px = (k1 * _x - _y - k * x[i] + y[i]) / (k1 - k), py = k * (px - x[i]) + y[i]; } double ers = dis(px, py, x[i], y[i]) + dis(px, py, x[i + 1], y[i + 1]) - dis(x[i], y[i], x[i + 1], y[i + 1]); if (abs(ers) < eps) { double d = dis(px, py, _x, _y); mins = min(mins, d); maxs = max(maxs, d); } } double ans = M_PI * (maxs * maxs - mins * mins); printf("%.20lf\n", ans); } }
#include <bits/stdc++.h> const double EPS = 1e-10; const long long int MOD = 1000000007ll; const long long int mod1 = 1000000009ll; const long long int mod2 = 1100000009ll; const double PI = 3.14159265359; int INF = 2147483645; long long int INFINF = 9223372036854775807; int debug = 0; using namespace std; long long int bit_count(long long int _x) { long long int _ret = 0; while (_x) { if (_x % 2 == 1) _ret++; _x /= 2; } return _ret; } long long int bit(long long int _mask, long long int _i) { return (_mask & (1 << _i)) == 0 ? 0 : 1; } long long int powermod(long long int _a, long long int _b, long long int _m) { long long int _r = 1; while (_b) { if (_b % 2 == 1) _r = (_r * _a) % _m; _b /= 2; _a = (_a * _a) % _m; } return _r; } long long int add(long long int a, long long int b) { long long int x = a + b; while (x >= MOD) x -= MOD; return x; } long long int sub(long long int a, long long int b) { long long int x = a - b; while (x < 0) x += MOD; return x; } long long int mul(long long int a, long long int b) { long long int x = a * b; x %= MOD; return x; } struct PT { long double x, y; PT() {} PT(long double x, long 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*(long double c) const { return PT(x * c, y * c); } PT operator/(long double c) const { return PT(x / c, y / c); } }; long double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; } long double dist2(PT p, PT q) { return dot(p - q, p - q); } long 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, long 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) { long 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))); } long long int n, px, py; long long int pointx[100010], pointy[100010]; int main() { srand(time(NULL)); scanf("%lld", &n); ; scanf("%lld", &px); ; scanf("%lld", &py); ; long double ans = 0.0; long double maxDist = -1e18, minDist = 1e18; cout << fixed << setprecision(15); for (int i = 0; i < n; i++) { long long int x, y; scanf("%lld", &x); ; scanf("%lld", &y); ; pointx[i] = x; pointy[i] = y; long double ddd = dist2(PT((long double)px, (long double)py), PT((long double)x, (long double)y)); ddd = sqrt((long double)ddd); if (ddd > maxDist) maxDist = ddd; if (ddd < minDist) minDist = ddd; } for (int i = 0; i < n; i++) { long long int x1 = pointx[i]; long long int y1 = pointy[i]; long long int x2 = pointx[(i + 1) % n]; long long int y2 = pointy[(i + 1) % n]; long double ddd = DistancePointSegment(PT((long double)x1, (long double)y1), PT((long double)x2, (long double)y2), PT((long double)px, (long double)py)); if (ddd > maxDist) maxDist = ddd; if (ddd < minDist) minDist = ddd; } ans = PI * (maxDist * maxDist - minDist * minDist); cout << ans; return 0; }
#include <bits/stdc++.h> double sq(double x) { return x * x; } int dbg = 1; using namespace std; pair<int, int> arr[100005]; double shortest(int x, int y, int a, int b) { double x1 = x, y1 = y, x2 = a, y2 = b; if (x1 == x2) if (y1 * y2 <= 0) return sq(x1); else return sq(min(y1, y2)) + sq(x1); double m = (y2 - y1) / (x2 - x1); double c = y1 - m * x1; if ((m * y1 + x1) * (m * y2 + x2) < 0) { double x, y; x = -1 * (m * c) / (1 + sq(m)); y = c / (1 + sq(m)); return sq(x) + sq(y); } return min(sq(x1) + sq(y1), sq(x2) + sq(y2)); } int main() { int n, x, y; double mini = 1e15, maxi = 0, pi = 3.1415926535897932; cin >> n >> x >> y; for (int i = 0; i < n; i++) { scanf("%d %d", &arr[i].first, &arr[i].second); ; arr[i].first -= x; arr[i].second -= y; } for (int i = 0; i < n - 1; i++) { mini = min(mini, shortest(arr[i].first, arr[i].second, arr[i + 1].first, arr[i + 1].second)); maxi = max(maxi, sq(arr[i].first) + sq(arr[i].second)); } maxi = max(maxi, sq(arr[n - 1].first) + sq(arr[n - 1].second)); mini = min(mini, shortest(arr[0].first, arr[0].second, arr[n - 1].first, arr[n - 1].second)); printf("%.9lf\n", pi * (maxi - mini)); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxN = 100100; const long double INF = 1e100; const long double eps = 1e-6; const long double PI = 3.14159265358979323846264338328; long long x[maxN], y[maxN]; long double Dis(long long a, long long b, long long p, long long q) { long double aa = 1.0 * a, bb = 1.0 * b, pp = 1.0 * p, qq = 1.0 * q; return (aa - pp) * (aa - pp) + (bb - qq) * (bb - qq); } long double DfromL(long long X1, long long Y1, long long aa, long long bb, long long pp, long long qq) { long double X = 1.0 * X1, Y = 1.0 * Y1, a = 1.0 * aa, b = 1.0 * bb, p = 1.0 * pp, q = 1.0 * qq; bool Inf = (a == p); long double m = (Inf) ? INF : ((b - q) / (a - p)); long double c = (Inf) ? INF : ((b - m * a)); bool zero = (!Inf && m == 0.0); long double m1 = (Inf) ? (0) : (zero) ? INF : (-1.0 / m); long double c1 = (Inf) ? (Y) : (zero) ? INF : (Y - m1 * X); long double XX = (Inf) ? (a) : (zero) ? (X) : ((c1 - c) / (m - m1)); long double YY = (Inf) ? (Y) : (zero) ? (b) : ((m * c1 - m1 * c) / (m - m1)); if (XX >= min(a, p) && XX <= max(a, p) && YY >= min(b, q) && YY <= max(b, q)) { if (Inf) return (X - XX) * (X - XX); if (zero) return (Y - YY) * (Y - YY); return ((m * X - Y + c) * (m * X - Y + c)) / (1.0 + m * m); } else return -1.0; } int main() { ios::sync_with_stdio(false); long long n, X, Y; cin >> n >> X >> Y; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; long double maxR = -1.0, minR = INF; for (int i = 0; i < n; i++) { long double dis = Dis(X, Y, x[i], y[i]); maxR = max(maxR, dis); minR = min(minR, dis); long double diS = DfromL(X, Y, x[i], y[i], x[(i + 1) % n], y[(i + 1) % n]); if (diS != -1.0) { maxR = max(maxR, diS); minR = min(minR, diS); } } long double ans = PI * (maxR - minR); cout << setprecision(20) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100010; struct vec { long double x, y; vec(double x = 0, double y = 0) : x(x), y(y) {} inline long double mo() { return ((x) * (x)) + ((y) * (y)); } vec operator-(const vec &a) const { vec ret; ret.x = x - a.x; ret.y = y - a.y; return ret; } vec operator*(const double &a) const { return vec(x * a, y * a); } inline long double dot(const vec &a) const { return x * a.x + y * a.y; } }; vec p, a[maxn]; int main() { int n; cin >> n >> p.x >> p.y; long double wai = 0, nei = 1e14; for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y; for (int i = 0; i < n; i++) { wai = max(wai, (a[i] - p).mo()); int j = (i + 1) % n; vec ip = p - a[i]; vec ij = a[j] - a[i]; long double t = ip.dot(ij) / ij.mo(); long double tmp; if (t < -1e-6) tmp = ip.mo(); else if (t > 1 + 1e-6) tmp = (a[j] - p).mo(); else tmp = (ip - ij * t).mo(); nei = min(nei, tmp); } cout << fixed << setprecision(6) << (wai - nei) * acos(-1) << endl; return 0; }
#include <bits/stdc++.h> const double EPS = 1e-10; const long long int MOD = 1000000007ll; const long long int mod1 = 1000000009ll; const long long int mod2 = 1100000009ll; int INF = 2147483645; long long int INFINF = 9223372036854775807; int debug = 0; using namespace std; long long int bit_count(long long int _x) { long long int _ret = 0; while (_x) { if (_x % 2 == 1) _ret++; _x /= 2; } return _ret; } long long int bit(long long int _mask, long long int _i) { return (_mask & (1 << _i)) == 0 ? 0 : 1; } long long int powermod(long long int _a, long long int _b, long long int _m) { long long int _r = 1; while (_b) { if (_b % 2 == 1) _r = (_r * _a) % _m; _b /= 2; _a = (_a * _a) % _m; } return _r; } long long int add(long long int a, long long int b) { long long int x = a + b; while (x >= MOD) x -= MOD; return x; } long long int sub(long long int a, long long int b) { long long int x = a - b; while (x < 0) x += MOD; return x; } long long int mul(long long int a, long long int b) { long long int x = a * b; x %= MOD; return x; } struct PT { long double x, y; PT() {} PT(long double x, long 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*(long double c) const { return PT(x * c, y * c); } PT operator/(long double c) const { return PT(x / c, y / c); } }; long double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; } long double dist2(PT p, PT q) { return dot(p - q, p - q); } long 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, long 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) { long 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))); } long long int n, px, py; long long int pointx[100010], pointy[100010]; const long double PI = acos(-1.0); int main() { srand(time(NULL)); scanf("%lld", &n); ; scanf("%lld", &px); ; scanf("%lld", &py); ; long double ans = 0.0; long double maxDist = -1e18, minDist = 1e18; cout << fixed << setprecision(20); for (int i = 0; i < n; i++) { long long int x, y; scanf("%lld", &x); ; scanf("%lld", &y); ; pointx[i] = x; pointy[i] = y; long double ddd = dist2(PT((long double)px, (long double)py), PT((long double)x, (long double)y)); ddd = sqrt((long double)ddd); if (ddd > maxDist) maxDist = ddd; if (ddd < minDist) minDist = ddd; } for (int i = 0; i < n; i++) { long long int x1 = pointx[i]; long long int y1 = pointy[i]; long long int x2 = pointx[(i + 1) % n]; long long int y2 = pointy[(i + 1) % n]; long double ddd = DistancePointSegment(PT((long double)x1, (long double)y1), PT((long double)x2, (long double)y2), PT((long double)px, (long double)py)); if (ddd > maxDist) maxDist = ddd; if (ddd < minDist) minDist = ddd; } ans = PI * (maxDist * maxDist - minDist * minDist); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int n; double px, py; double r = 1000000, R = 0; double x[1110111], y[1110111]; double Pl(int i, int j) { return fabs((x[j] - x[i]) * (py - y[i]) - (y[j] - y[i]) * (px - x[i])); } double Dist(int i, int j) { double a = hypot(x[i] - px, y[i] - py); double b = hypot(x[j] - px, y[j] - py); double c = hypot(x[i] - x[j], y[i] - y[j]); if (a * a <= c * c + b * b && b * b <= a * a + c * c) return Pl(i, j) / c; return min(hypot(x[i] - px, y[i] - py), hypot(x[j] - px, y[j] - py)); } void find_r() { x[n + 1] = x[1], y[n + 1] = y[1]; for (int i = 1; i <= n; i++) { r = min(r, Dist(i, i + 1)); } } void find_R() { for (int i = 1; i <= n; i++) R = max(R, hypot(x[i] - px, y[i] - py)); } int main() { cin >> n >> px >> py; for (int i = 1; i <= n; i++) cin >> x[i] >> y[i]; find_R(); find_r(); R *= R; r *= r; cout << fixed << setprecision(6) << (R - r) * M_PI; 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 sqrt((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 = sqrt((p2.y - p1.y) * (p2.y - p1.y) + (p2.x - p1.x) * (p2.x - p1.x)); return 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 * maxx) - (acos(-1) * minn * minn); printf("%0.10lf\n", an); return 0; }
#include <bits/stdc++.h> const long long inf = 0x3f3f3f3f3f3f3f3f; inline double max(double a, double b) { return a > b ? a : b; } inline double min(double a, double b) { return a < b ? a : b; } double pow2(double a) { return a * a; } struct point { long long x, y; point(long long x = 0, long long y = 0) : x(x), y(y) {} point operator-(const point other) { return point(x - other.x, y - other.y); } }; struct line { point a, 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 double dis(point p, line v) { return pow2((v.a.x - p.x) * (v.b.y - p.y) - (v.b.x - p.x) * (v.a.y - p.y)) / dis(v.b, v.a); } inline long long dot(point a, point b) { return a.x * b.x + a.y * b.y; } int main() { int n; point p, tmp, first, front; double dismin = inf, dismax = -inf, distmp; scanf("%d%lld%lld", &n, &p.x, &p.y); for (int i = 0; i < n; i++) { scanf("%lld%lld", &tmp.x, &tmp.y); distmp = dis(p, tmp); dismin = min(dismin, distmp); dismax = max(dismax, distmp); if (i && dot(tmp - p, tmp - front) > 0 && dot(front - p, front - tmp) > 0) { distmp = dis(p, line{front, tmp}); dismin = min(dismin, distmp); dismax = max(dismax, distmp); } if (!i) first = tmp; front = tmp; } if (dot(tmp - p, tmp - first) > 0 && dot(first - p, first - tmp) > 0) { distmp = dis(p, line{first, tmp}); dismin = min(dismin, distmp); dismax = max(dismax, distmp); } printf("%.18f\n", acos(-1) * (dismax - dismin)); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; struct Point { double x, y; } p[maxn]; double a, b; int n; double GetPointDistance(Point p1, Point p2) { return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); } double GetNearestDistance(Point PA, Point PB, Point P3) { double a, b, c; a = GetPointDistance(PB, P3); if (a <= 0.00001) return 0.0f; b = GetPointDistance(PA, P3); if (b <= 0.00001) return 0.0f; c = GetPointDistance(PA, PB); if (c <= 0.00001) return a; if (a * a >= b * b + c * c) return b; if (b * b >= a * a + c * c) return a; double l = (a + b + c) / 2; double s = sqrt(l * (l - a) * (l - b) * (l - c)); return 2 * s / c; } int main() { double Max = -1; double Min = -1; scanf("%d%lf%lf", &n, &a, &b); Point T; T.x = a; T.y = b; for (int i = 0; i < n; i++) scanf("%lf%lf", &p[i].x, &p[i].y); for (int i = 0; i < n; i++) { if (i == n - 1) { double MinLen = GetNearestDistance(p[0], p[i], T); if (Min == -1) Min = MinLen; else Min = min(Min, MinLen); double Len1 = sqrt((p[i].x - a) * (p[i].x - a) + (p[i].y - b) * (p[i].y - b)); double Len2 = sqrt((p[0].x - a) * (p[0].x - a) + (p[0].y - b) * (p[0].y - b)); double MaxLen = max(Len1, Len2); if (Max == -1) Max = MaxLen; else Max = max(Max, MaxLen); } else { double MinLen = GetNearestDistance(p[i + 1], p[i], T); if (Min == -1) Min = MinLen; else Min = min(Min, MinLen); double Len1 = sqrt((p[i].x - a) * (p[i].x - a) + (p[i].y - b) * (p[i].y - b)); double Len2 = sqrt((p[i + 1].x - a) * (p[i + 1].x - a) + (p[i + 1].y - b) * (p[i + 1].y - b)); double MaxLen = max(Len1, Len2); if (Max == -1) Max = MaxLen; else Max = max(Max, MaxLen); } } printf("%lf\n", 3.1415926 * (Max * Max - Min * Min)); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; const double PI = acos(-1); const double eps = 1e-8; inline int dcmp(double x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; } struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} bool operator==(const Point& tmp) const { return dcmp(x - tmp.x) == 0 && dcmp(y - tmp.y) == 0; } Point operator-(const Point& tmp) const { return Point(x - tmp.x, y - tmp.y); } } org, cur, last, first; int n; double maxx, minn = 1000000; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline double Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; } inline double Length(Point A) { return sqrt(Dot(A, A)); } inline double Cross(Point A, Point B) { return A.x * B.y - A.y * B.x; } inline double Inter(Point A, Point B) { if (A == B) return Length(org - A); Point v1 = B - A, v2 = org - A, v3 = org - B; if (dcmp(Dot(v1, v2)) < 0 || dcmp(Dot(v1, v3)) > 0) return min(Length(v2), Length(v3)); return fabs(Cross(v1, v2)) / Length(v1); } int main() { n = read(), org.x = read(), org.y = read(); first.x = read(), first.y = read(); double tmp = sqrt((first.x - org.x) * (first.x - org.x) + (first.y - org.y) * (first.y - org.y)); maxx = max(maxx, tmp); last = first; while (--n) { cur.x = read(), cur.y = read(); double tmp = sqrt((cur.x - org.x) * (cur.x - org.x) + (cur.y - org.y) * (cur.y - org.y)); maxx = max(maxx, tmp); minn = min(minn, Inter(last, cur)); last = cur; } last = cur; cur = first; minn = min(minn, Inter(last, cur)); printf("%.8lf", PI * (maxx * maxx - minn * minn)); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const double INF = 1e100; const double EPS = 1e-12; struct pt { double x, y; pt() {} pt(double a, double b) : x(a), y(b) {} pt operator+(pt p) { return pt(x + p.x, y + p.y); } pt operator-(pt p) { return pt(x - p.x, y - p.y); } pt operator*(double r) { return pt(r * x, r * y); } }; 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); } pt ProjectPointSegment(pt a, pt b, pt c) { double r = dist2(b, a); if (fabs(r) < EPS) return a; r = dot(c - a, b - a) / r; if (r < 0) return a; if (r > 1) return b; return a + (b - a) * r; } double DistancePointSegment(pt a, pt b, pt c) { return sqrt(dist2(c, ProjectPointSegment(a, b, c))); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(10); int n; pt p; cin >> n >> p.x >> p.y; vector<pt> P(n); for (int i = 0; i < n; i++) cin >> P[i].x >> P[i].y; double dmin = INF, dmax = -INF; for (int i = 0; i < n; i++) { int j = (i + 1) % n; dmin = min(dmin, DistancePointSegment(P[i], P[j], p)); dmin = min(dmin, hypot(P[i].x - p.x, P[i].y - p.y)); dmax = max(dmax, DistancePointSegment(P[i], P[j], p)); dmax = max(dmax, hypot(P[i].x - p.x, P[i].y - p.y)); } cout << pi * (dmax * dmax - dmin * dmin) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long double getdist(long double x1, long double y1, long double x2, long double y2) { return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } void run() { cin.sync_with_stdio(false); long long n; cin >> n; long double x, y; cin >> x >> y; long double mindist = 1e9; long double maxdist = 0; long double minx, miny, maxx, maxy; long double prevx, prevy, nowx, nowy; long double startx, starty; cin >> nowx >> nowy; startx = nowx; starty = nowy; if (getdist(x, y, nowx, nowy) >= maxdist) { maxdist = getdist(x, y, nowx, nowy); } if (getdist(x, y, nowx, nowy) <= mindist) { mindist = getdist(x, y, nowx, nowy); } for (int i = 0; i < n; i++) { prevx = nowx; prevy = nowy; cin >> nowx >> nowy; if (getdist(x, y, nowx, nowy) >= maxdist) { maxdist = getdist(x, y, nowx, nowy); } if (getdist(x, y, nowx, nowy) <= mindist) { mindist = getdist(x, y, nowx, nowy); } long double d1 = getdist(x, y, nowx, nowy); long double d2 = getdist(x, y, prevx, prevy); long double d3 = getdist(nowx, nowy, prevx, prevy); long double p = (d1 + d2 + d3) / 2; long double h = (2 * sqrt(p * (p - d1) * (p - d2) * (p - d3))) / d3; if (d1 * d1 + d3 * d3 >= d2 * d2 && d2 * d2 + d3 * d3 >= d1 * d1 && h <= mindist) { mindist = h; } } prevx = nowx; prevy = nowy; nowx = startx; nowy = starty; if (getdist(x, y, nowx, nowy) >= maxdist) { maxdist = getdist(x, y, nowx, nowy); } if (getdist(x, y, nowx, nowy) <= mindist) { mindist = getdist(x, y, nowx, nowy); } long double d1 = getdist(x, y, nowx, nowy); long double d2 = getdist(x, y, prevx, prevy); long double d3 = getdist(nowx, nowy, prevx, prevy); long double p = (d1 + d2 + d3) / 2; long double h = (2 * sqrt(p * (p - d1) * (p - d2) * (p - d3))) / d3; if (d1 * d1 + d3 * d3 >= d2 * d2 && d2 * d2 + d3 * d3 >= d1 * d1 && h <= mindist) { mindist = h; } cout << fixed << setprecision(50) << maxdist * maxdist * 3.141592653589793238462643383279 - mindist * mindist * 3.141592653589793238462643383279; } void pre() { if (strcmp("", "") != 0) { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } } void post() { fprintf(stderr, "Execution time: %Lf", (long double)clock() / CLOCKS_PER_SEC); } int main() { pre(); run(); post(); return 0; }
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846264338; struct hehe { long long x, y; } p[100005]; int n; double maxr, minr, ans; long long cross(hehe p1, hehe p2, hehe p3) { return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y); } long long dc(hehe p1, hehe p2, hehe p3) { return (p2.x - p1.x) * (p3.x - p1.x) + (p2.y - p1.y) * (p3.y - p1.y); } double dis(hehe p1, hehe p2) { return sqrt( (double)((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y))); } void solve(int a, int b) { double da, db, h; long long dc1, dc2; da = dis(p[a], p[0]); db = dis(p[b], p[0]); h = (double)fabs(cross(p[0], p[a], p[b])) / dis(p[a], p[b]); dc1 = dc(p[a], p[0], p[b]); dc2 = dc(p[b], p[0], p[a]); if (da > db) swap(da, db); if (dc1 < 0 || dc2 < 0) { maxr = max(maxr, db); minr = min(minr, da); } else { maxr = max(maxr, db); minr = min(minr, h); } } int main() { int i; cin >> n >> p[0].x >> p[0].y; maxr = 0; minr = 0x7ffffffff; for (i = 1; i <= n; i++) cin >> p[i].x >> p[i].y; for (i = 1; i <= n - 1; i++) solve(i, i + 1); solve(1, n); ans = (maxr * maxr - minr * minr) * pi; printf("%.18f", ans); return 0; }
#include <bits/stdc++.h> using namespace std; long long i, n; double l, r, mid, ans, maxd, mind = 1e18, a, b, x[100010], y[100010]; bool pd(double len, double x, double y, double xx, double yy) { double aa = yy - y, bb = x - xx, cc = xx * y - x * yy, dis, ans1, ans2, lena, lenb, lenc; if (min((x - a) * (x - a) + (y - b) * (y - b), (xx - a) * (xx - a) + (yy - b) * (yy - b)) < len * len) return 1; dis = (aa * a + bb * b + cc) / sqrt(aa * aa + bb * bb); if (dis < 0) dis = -dis; if (dis > len) return 0; lena = (xx - a) * (xx - a) + (yy - b) * (yy - b); lenb = (x - a) * (x - a) + (y - b) * (y - b); lenc = (xx - x) * (xx - x) + (yy - y) * (yy - y); ans1 = (lenb + lenc - lena) / (2 * sqrt(lenb * lenc)); ans2 = (lena + lenc - lenb) / (2 * sqrt(lena * lenc)); if (ans1 > 0 && ans2 > 0) return 1; else return 0; } int main() { scanf("%lld%lf%lf", &n, &a, &b); for (i = 1; i <= n; i++) { scanf("%lf%lf", &x[i], &y[i]); maxd = max<double>(maxd, (x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b)); } x[n + 1] = x[1]; y[n + 1] = y[1]; for (i = 1; i <= n; i++) { l = 0; r = sqrt( max((x[i] - a) * (x[i] - a) + (y[i] - b) * (y[i] - b), (x[i + 1] - a) * (x[i + 1] - a) + (y[i + 1] - b) * (y[i + 1] - b))); ans = 1e18; while (r - l > 1e-8) { mid = (l + r) / 2; if (pd(mid, x[i], y[i], x[i + 1], y[i + 1])) { ans = mid; r = mid; } else l = mid; } mind = min<double>(mind, ans * ans); } printf("%.17lf\n", 3.1415926535897932384626433832795 * (maxd - mind)); }
#include <bits/stdc++.h> using namespace std; double max(double a, double b) { return a > b ? a : b; } double min(double a, double b) { return a < b ? a : b; } double sqr(double x) { return x * x; } int n, i, x[100010], y[100010]; double xx, yy, minn, maxx, a, b, k, c, A, B, now1, now2, now3, x0, Y0; int main() { double pi = 2.0 * acos(0.0); scanf("%d", &n); scanf("%lf%lf", &x0, &Y0); for (i = 1; i <= n; i++) scanf("%d%d", &x[i], &y[i]); x[n + 1] = x[1]; y[n + 1] = y[1]; maxx = sqr(x[1] - x0) + sqr(y[1] - Y0); minn = maxx; for (i = 1; i <= n; i++) { if (x[i] == x[i + 1]) { double now = sqr(x0 - x[i]); if ((Y0 >= y[i] && Y0 <= y[i + 1]) || (Y0 <= y[i] && Y0 >= y[i + 1])) { minn = min(minn, now); maxx = max(maxx, now + (max(sqr(Y0 - y[i]), sqr(Y0 - y[i + 1])))); } else { if (Y0 > y[i]) { if (y[i] > y[i + 1]) { a = y[i]; b = y[i + 1]; } else { b = y[i]; a = y[i + 1]; } minn = min(minn, now + sqr(Y0 - a)); maxx = max(maxx, now + sqr(Y0 - b)); } else { if (y[i] < y[i + 1]) { a = y[i]; b = y[i + 1]; } else { b = y[i]; a = y[i + 1]; } minn = min(minn, now + sqr(Y0 - a)); maxx = max(maxx, now + sqr(Y0 - b)); } } } else { k = (y[i + 1] * 1.0 - y[i] * 1.0) / (x[i + 1] * 1.0 - x[i] * 1.0); if (x[i] < x[i + 1]) { a = x[i]; b = x[i + 1]; } else { b = x[i]; a = x[i + 1]; } c = y[i + 1] - k * x[i + 1]; A = 1.0 + sqr(k); B = 2 * c * k - 2 * x0 - 2 * k * Y0; xx = -B / (2.0 * A); yy = k * xx + c; now1 = sqr(xx - x0) + sqr(yy - Y0); now2 = sqr(x[i] - x0) + sqr(y[i] - Y0); now3 = sqr(x[i + 1] - x0) + sqr(y[i + 1] - Y0); minn = min(minn, min(now2, now3)); maxx = max(maxx, max(now2, now3)); if (a <= xx && xx <= b) { minn = min(minn, now1); maxx = max(maxx, now1); } } } printf("%.18lf\n", pi * (maxx - minn)); return 0; }
#include <bits/stdc++.h> using namespace std; double n, x, y, a, b; vector<pair<double, double> > v; set<double> s; 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 (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() { cin >> n >> x >> y; for (int i = 0; i < n; i++) { cin >> a >> b; v.push_back(make_pair(a, b)); } for (int i = 0; i < n; i++) { s.insert((x - v[i].first) * (x - v[i].first) + (y - v[i].second) * (y - v[i].second)); } for (int i = 0; i < n - 1; i++) { double ans = FindDistanceToSegment(v[i].first, v[i].second, v[i + 1].first, v[i + 1].second, x, y); s.insert(ans); } double ans = FindDistanceToSegment(v[0].first, v[0].second, v[n - 1].first, v[n - 1].second, x, y); s.insert(ans); double fi = *s.begin(); double ff = *s.rbegin(); cout << setprecision(24) << 3.14159265358979323846 * (ff - fi) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1E-8; const int dx4[4] = {1, 0, 0, -1}; const int dy4[4] = {0, -1, 1, 0}; const int inf = 0x3f3f3f3f; const int N = 1E5 + 7; const double PI = acos(-1.0); int dblcmp(double d) { return d < -eps ? -1 : d > eps; } struct point { double x, y; point() {} point(double _x, double _y) : x(_x), y(_y){}; void input() { cin >> x >> y; } point sub(point p) { return point(x - p.x, y - p.y); } double dot(point p) { return x * p.x + y * p.y; } double distance2(point p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } double distance(point p) { return hypot(x - p.x, y - p.y); } double det(point p) { return x * p.y - y * p.x; } } p[N], q; double sqr(double x) { return x * x; } struct line { point a, b; line() {} line(point _a, point _b) { a = _a; b = _b; } double length() { return a.distance(b); } double dispointtoline2(point p) { double res = sqr(fabs(p.sub(a).det(b.sub(a))) / length()); return res; } double dispointtoseg2(point p) { if (dblcmp(p.sub(b).dot(a.sub(b))) < 0 || dblcmp(p.sub(a).dot(b.sub(a))) < 0) return min(p.distance2(a), p.distance2(b)); return dispointtoline2(p); } } li[N]; int n; int main() { cin >> n; q.input(); double MIN = 99999999999999999; double MAX = -1; for (int i = 1; i <= n; i++) { p[i].input(); double d = p[i].distance2(q); MAX = max(MAX, d); } for (int i = 1; i <= n - 1; i++) { li[i] = line(p[i], p[i + 1]); } li[n] = line(p[n], p[1]); for (int i = 1; i <= n; i++) { double d = li[i].dispointtoseg2(q); MIN = min(MIN, d); } double ans = (MAX - MIN) * PI; printf("%.18f\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline void Read(T &x) { int f = 1; char t = getchar(); while (t < '0' || t > '9') { if (t == '-') f = -1; t = getchar(); } x = 0; while (t >= '0' && t <= '9') { x = x * 10 + t - '0'; t = getchar(); } x *= f; } template <class T> inline void chkmin(T &x, T y) { if (x > y) x = y; } template <class T> inline void chkmax(T &x, T y) { if (x < y) x = y; } const int maxn = 200005; const double inf = 2e18; const double pi = acos(-1.0); struct point { long double x, y; point() {} point(long double x, long double y) : x(x), y(y) {} void read() { cin >> x >> y; } }; point operator+(const point &a, const point &b) { return point(a.x + b.x, a.y + b.y); } point operator-(const point &a, const point &b) { return point(a.x - b.x, a.y - b.y); } point operator*(const point &a, long double v) { return point(a.x * v, a.y * v); } point operator/(const point &a, long double v) { return point(a.x / v, a.y / v); } long double operator^(const point &a, const point &b) { return a.x * b.y - a.y * b.x; } int n; point P, g[maxn]; long double dis(point &a, point &b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } long double maxr = -inf, minr = inf; void calc(point &a, point &b) { long double A = dis(a, P), B = dis(b, P), C = dis(a, b); long double area = (a - P) ^ (b - P); long double Height = area * area / C; if (A < B) swap(A, B); if (A > B + C) return; chkmax(maxr, Height); chkmin(minr, Height); } void input() { Read(n); P.read(); for (register int i = 1; i <= n; i++) g[i].read(); g[0] = g[n]; for (register int i = 1; i <= n; i++) calc(g[i], g[i - 1]); } void solve() { for (register int i = 1; i <= n; i++) { chkmax(maxr, dis(g[i], P)); chkmin(minr, dis(g[i], P)); } printf("%.18lf\n", (double)(maxr - minr) * pi); } int main() { input(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; double DEG_to_RAD(double d) { return d * acos(-1.0) / 180.0; } double RAD_to_DEG(double r) { return r * 180.0 / acos(-1.0); } struct point_i { int x, y; point_i() { x = y = 0; } point_i(int _x, int _y) : x(_x), y(_y) {} }; struct point { double x, y; point() { x = y = 0.0; } point(double _x, double _y) : x(_x), y(_y) {} bool operator<(point other) const { if (fabs(x - other.x) > 1e-9) return x < other.x; return y < other.y; } bool operator==(point other) const { return (fabs(x - other.x) < 1e-9 && (fabs(y - other.y) < 1e-9)); } }; double dist(point p1, point p2) { return hypot(p1.x - p2.x, p1.y - p2.y); } point rotate(point p, double theta) { double rad = DEG_to_RAD(theta); return point(p.x * cos(rad) - p.y * sin(rad), p.x * sin(rad) + p.y * cos(rad)); } struct line { double a, b, c; }; void pointsToLine(point p1, point p2, line &l) { if (fabs(p1.x - p2.x) < 1e-9) { l.a = 1.0; l.b = 0.0; l.c = -p1.x; } else { l.a = -(double)(p1.y - p2.y) / (p1.x - p2.x); l.b = 1.0; l.c = -(double)(l.a * p1.x) - p1.y; } } struct line2 { double m, c; }; int pointsToLine2(point p1, point p2, line2 &l) { if (abs(p1.x - p2.x) < 1e-9) { l.m = 1e9; l.c = p1.x; return 0; } else { l.m = (double)(p1.y - p2.y) / (p1.x - p2.x); l.c = p1.y - l.m * p1.x; return 1; } } bool areParallel(line l1, line l2) { return (fabs(l1.a - l2.a) < 1e-9) && (fabs(l1.b - l2.b) < 1e-9); } bool areSame(line l1, line l2) { return areParallel(l1, l2) && (fabs(l1.c - l2.c) < 1e-9); } bool areIntersect(line l1, line l2, point &p) { if (areParallel(l1, l2)) return false; p.x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b); if (fabs(l1.b) > 1e-9) p.y = -(l1.a * p.x + l1.c); else p.y = -(l2.a * p.x + l2.c); return true; } struct vec { double x, y; vec(double _x, double _y) : x(_x), y(_y) {} }; vec toVec(point a, point b) { return vec(b.x - a.x, b.y - a.y); } vec scale(vec v, double s) { return vec(v.x * s, v.y * s); } point translate(point p, vec v) { return point(p.x + v.x, p.y + v.y); } void pointSlopeToLine(point p, double m, line &l) { l.a = -m; l.b = 1; l.c = -((l.a * p.x) + (l.b * p.y)); } void closestPoint(line l, point p, point &ans) { line perpendicular; if (fabs(l.b) < 1e-9) { ans.x = -(l.c); ans.y = p.y; return; } if (fabs(l.a) < 1e-9) { ans.x = p.x; ans.y = -(l.c); return; } pointSlopeToLine(p, 1 / l.a, perpendicular); areIntersect(l, perpendicular, ans); } void reflectionPoint(line l, point p, point &ans) { point b; closestPoint(l, p, b); vec v = toVec(p, b); ans = translate(translate(p, v), v); } double dot(vec a, vec b) { return (a.x * b.x + a.y * b.y); } double norm_sq(vec v) { return v.x * v.x + v.y * v.y; } double distToLine(point p, point a, point b, point &c) { vec ap = toVec(a, p), ab = toVec(a, b); double u = dot(ap, ab) / norm_sq(ab); c = translate(a, scale(ab, u)); return dist(p, c); } double distToLineSegment(point p, point a, point b, point &c) { vec ap = toVec(a, p), ab = toVec(a, b); double u = dot(ap, ab) / norm_sq(ab); if (u < 0.0) { c = point(a.x, a.y); return dist(p, a); } if (u > 1.0) { c = point(b.x, b.y); return dist(p, b); } return distToLine(p, a, b, c); } double angle(point a, point o, point b) { vec oa = toVec(o, a), ob = toVec(o, b); return acos(dot(oa, ob) / sqrt(norm_sq(oa) * norm_sq(ob))); } double cross(vec a, vec b) { return a.x * b.y - a.y * b.x; } bool ccw(point p, point q, point r) { return cross(toVec(p, q), toVec(p, r)) > 0; } bool collinear(point p, point q, point r) { return fabs(cross(toVec(p, q), toVec(p, r))) < 1e-9; } double min(double a, double b, double c) { if (a <= b && a <= c) return a; if (b <= a && b <= c) return b; return c; } double max(double a, double b) { if (a >= b) return a; return b; } int main() { int n; cin >> n; double pX, pY; cin >> pX >> pY; double lX, lY, nX, nY; cin >> lX >> lY; double flX, flY; flX = lX; flY = lY; point p(pX, pY); point pl(lX, lY); double minD = dist(p, pl); double maxD = dist(p, pl); n--; point p4; while (n--) { cin >> nX >> nY; point p2(lX, lY); point p3(nX, nY); double disP = distToLineSegment(p, p2, p3, p4); double disPnt = dist(p3, p); minD = min(minD, disPnt, disP); maxD = max(disPnt, maxD); lX = nX; lY = nY; } point p_f(flX, flY); point p_n(nX, nY); double fP = distToLineSegment(p, p_f, p_n, p4); minD = min(minD, fP); double ans = acos(-1.0) * ((maxD * maxD * 1.0000) - (minD * minD * 1.000)); printf("%.11lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; double INF = 1e100; double EPS = 1e-12; struct PT { double x, y; PT() {} PT(double x, double y) : x(x), y(y) {} PT(const PT &p) : x(p.x), y(p.y) {} PT operator+(const PT &p) const { return PT(x + p.x, y + p.y); } PT operator-(const PT &p) const { return PT(x - p.x, y - p.y); } PT operator*(double c) const { return PT(x * c, y * c); } PT operator/(double c) const { return PT(x / c, y / c); } }; double dot(PT p, PT q) { return p.x * q.x + p.y * q.y; } double dist2(PT p, PT q) { return dot(p - q, p - q); } PT ProjectPointSegment(PT a, PT b, PT c) { double r = dot(b - a, b - a); if (fabs(r) < EPS) return a; r = dot(c - a, b - a) / r; if (r < 0) return a; if (r > 1) return b; return a + (b - a) * r; } double DistancePointSegment(PT a, PT b, PT c) { return sqrt(dist2(c, ProjectPointSegment(a, b, c))); } long long dis(pair<long long, long long> p1, pair<long long, long long> p2) { long long res; long long x = p1.first - p2.first; long long y = p2.second - p1.second; res = (x * x) + (y * y); return res; } vector<pair<long long, long long> > v; long long n; int main() { cin >> n; double ans = M_PI; long long cx, cy; cin >> cx >> cy; for (long long i = 0; i < n; i++) { long long x, y; cin >> x >> y; v.push_back(make_pair(x, y)); } long long area = 0; pair<long long, long long> pp; pp = make_pair(cx, cy); long long mx = dis(pp, v[0]); for (int i = 1; i < n; i++) { mx = max(mx, dis(pp, v[i])); } double mndis = DistancePointSegment(PT(v[0].first, v[0].second), PT(v[1].first, v[1].second), PT(cx, cy)); for (int i = 1; i < n - 1; i++) { mndis = min(mndis, DistancePointSegment(PT(v[i].first, v[i].second), PT(v[1 + i].first, v[i + 1].second), PT(cx, cy))); } mndis = min(mndis, DistancePointSegment(PT(v[0].first, v[0].second), PT(v[n - 1].first, v[n - 1].second), PT(cx, cy))); double mdis = sqrt((double)mx); ans = ans * ((mdis * mdis) - (mndis * mndis)); printf("%.10lf\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1); struct Point { long long x; long long y; Point() { x = -1; y = -1; } Point(long long x_, long long y_) { x = x_; y = y_; } void scan() { cin >> x >> y; } Point operator-(const Point &other) const { return Point(x - other.x, y - other.y); } long long operator%(const Point &other) const { return x * other.x + y * other.y; } long long operator*(const Point &other) const { return x * other.y - y * other.x; } long double dist(const Point &other) const { return hypot(x - other.x, y - other.y); } }; long double ar(const Point &a, const Point &b, const Point &c) { return abs((a - b) * (c - b)); } long double hh(const Point &a, const Point &b, const Point &c) { return ar(a, b, c) / b.dist(c); } bool ok_ang(const Point &a, const Point &b, const Point &c) { long long f = (b - a) % (c - a); long long s = (b - c) % (a - c); return f >= 0 && s >= 0; } long double solve(const Point &a, const Point &b, const Point &to) { long double ans = min(to.dist(a), to.dist(b)); if (ok_ang(a, to, b)) { ans = min(ans, hh(to, a, b)); } return ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; Point p; p.scan(); vector<Point> a(n); for (auto &t : a) { t.scan(); } long double mn = 1e18; long double mx = -1; for (auto t : a) { long double cur = p.dist(t); mn = min(mn, cur); mx = max(mx, cur); } for (long long i = 0; i < n; i++) { Point f = a[i]; Point s = a[(i + 1) % n]; long double cur = solve(f, s, p); mn = min(mn, cur); } cout << fixed << setprecision(16) << PI * (mx * mx - mn * mn) << endl; }
#include <bits/stdc++.h> using namespace std; const int dr[] = {-1, 1, 0, 0}; const int dc[] = {0, 0, 1, -1}; const int drd[] = {-1, -1, 1, 1}; const int dcd[] = {-1, 1, -1, 1}; const int MOD = 1e9 + 7; const int INF = 1e9; const int N = 1e5 + 5; const long double pi = acos(-1); const double eps = 1e-9; struct point { long double x, y; }; int n; point p[N], x; long double mx = -1, mn = 1e200, ans; long double sqr(long double x) { return x * x; } bool between(long double a, long double b, long double c) { if (c <= a && c >= b) return 1; if (c >= a && c <= b) return 1; return 0; } long double dispoint(point p1, point p2) { return sqr(p1.x - p2.x) + sqr(p1.y - p2.y); } long double gradient(point p1, point p2) { return (p2.y - p1.y) / (p2.x - p1.x); } long double dis(point p1, point p2, point p3) { long double d; point p4; if (p2.x == p1.x) { if (p2.x == p3.x) min(dispoint(p1, p3), dispoint(p2, p3)); if (between(p1.y, p2.y, p3.y)) return sqr(p3.x - p1.x); return min(dispoint(p1, p3), dispoint(p2, p3)); } if (p2.y == p1.y) { if (p2.y == p3.y) return min(dispoint(p1, p3), dispoint(p2, p3)); if (between(p1.x, p2.x, p3.x)) return sqr(p3.y - p1.y); return min(dispoint(p1, p3), dispoint(p2, p3)); } if (gradient(p1, p3) == gradient(p2, p1)) return min(dispoint(p1, p3), dispoint(p2, p3)); d = dispoint(p1, p2); long double a = ((p3.x - p1.x) * (p2.x - p1.x) + (p3.y - p1.y) * (p2.y - p1.y)); long double b = ((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y)); long double proj = a / b; p4.x = p1.x + proj * (p2.x - p1.x); p4.y = p1.y + proj * (p2.y - p1.y); if (dispoint(p1, p4) < d && dispoint(p2, p4) < d) return (dispoint(p3, p4)); return min(dispoint(p1, p3), dispoint(p2, p3)); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> x.x >> x.y; for (long long i = 1; i <= n; i++) { cin >> p[i].x >> p[i].y; mx = max(mx, sqr(x.x - p[i].x) + sqr(x.y - p[i].y)); mn = min(mn, sqr(x.x - p[i].x) + sqr(x.y - p[i].y)); } for (long long i = 1; i <= n - 1; i++) { mx = max(mx, (dis(p[i], p[i + 1], x))); mn = min(mn, (dis(p[i], p[i + 1], x))); } mx = max(mx, (dis(p[n], p[1], x))); mn = min(mn, (dis(p[n], p[1], x))); ans = pi * (mx - mn); cout << fixed << setprecision(6) << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int m, n; const double PI = 3.14159265358979; const int maxn = 100005; double x[maxn], y[maxn]; double g(int i, int j) { return x[i] * x[j] + y[i] * y[j]; } int main() { ios_base::sync_with_stdio(0); cout << fixed << setprecision(12); int dx, dy; cin >> n >> dx >> dy; for (int i = 0, _i = (n); i < _i; ++i) { cin >> x[i] >> y[i]; x[i] -= dx; y[i] -= dy; } x[n] = x[0]; y[n] = y[0]; double ma = 0, mi = (1LL << 60); for (int i = 0, _i = (n); i < _i; ++i) { ma = max(ma, x[i] * x[i] + y[i] * y[i]); mi = min(mi, x[i] * x[i] + y[i] * y[i]); if (min(g(i, i), g(i + 1, i + 1)) >= g(i, i + 1)) { double tmp = (x[i] * y[i + 1] - x[i + 1] * y[i]) / hypot(x[i + 1] - x[i], y[i + 1] - y[i]); mi = min(tmp * tmp, mi); } } cout << PI * (ma - mi) << "\n"; return 0; }
#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; 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); else mind = min(dist(i, j, x, y), 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> using namespace std; const int maxn = 100005; const double PI = acos(-1.0); int n; double Mx, Mn; struct point { int x, y; void re() { scanf("%d", &x); scanf("%d", &y); } }; point A[maxn]; double ds(point P, point Q) { return sqrt((double)(P.x - Q.x) * (P.x - Q.x) + (double)(P.y - Q.y) * (P.y - Q.y)); } int main() { scanf("%d", &n); A[0].re(), Mx = -1, Mn = 1e18; for (int i = 1; i <= n; i++) A[i].re(); A[n + 1] = A[1]; for (int i = 1; i <= n; i++) { double a = ds(A[i], A[0]); double b = ds(A[i + 1], A[0]); double c = ds(A[i], A[i + 1]); Mx = max(Mx, max(a, b)); if (a * a + c * c <= b * b) Mn = min(Mn, a); else if (b * b + c * c <= a * a) Mn = min(Mn, b); else { double p = (a + b + c) / 2.0; double s = sqrt(p * (p - a) * (p - b) * (p - c)); Mn = min(Mn, s * 2.0 / c); } } printf("%.15f", PI * (Mx * Mx - Mn * Mn)); return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; struct point { double x, y; point() { x = y = 0; } point(int X, int Y) { x = X, y = Y; } } p[110000], o; inline point V(point s, point e) { return point(e.x - s.x, e.y - s.y); } inline double crossP(point a, point b) { return a.x * b.y - a.y * b.x; } inline double dis(point a, point b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } int main(int argc, const char* argv[]) { int n; scanf("%d%lf%lf", &n, &o.x, &o.y); for (int i = 1; i <= n; i++) scanf("%lf%lf", &p[i].x, &p[i].y); p[n + 1] = p[1]; double R = 0, r = 1e20; for (int i = 1; i <= n; i++) { R = max(R, dis(p[i], o)); double l1 = dis(p[i], o), l2 = dis(p[i + 1], o), d = dis(p[i], p[i + 1]); double h = abs(crossP(V(o, p[i]), V(o, p[i + 1]))) / d; if (l1 * l1 + d * d < l2 * l2 + eps || l2 * l2 + d * d < l1 * l1 + eps) r = min(r, min(l1, l2)); else r = min(r, h); } printf("%.10lf\n", 3.14159265358979 * (R * R - r * r)); return 0; }
#include <bits/stdc++.h> using namespace std; long n, i, j; struct punct { long long x, y; } p, v[100006]; long ecd(punct a, punct b, punct p) { if ((b.y - a.y) * (p.x - a.x) - (b.x - a.x) * (p.y - a.y) < 0) return -1; else if ((b.y - a.y) * (p.x - a.x) - (b.x - a.x) * (p.y - a.y) > 0) return 1; return 0; } bool inPoligon(punct v[], long n, punct p) { long ok = 0; for (i = 1; i < n; i++) { if (ok == 0) ok = ecd(v[i], v[i + 1], p); else if (ok != ecd(v[i], v[i + 1], p)) return false; } if (ok != ecd(v[n], v[1], p)) return false; return true; } long long dist(punct a, punct b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } long double modul(long double x) { if (x < 0) return -x; return x; } long double distD(punct a, punct b, punct p) { long double x, y; x = modul((b.y - a.y) * p.x - (b.x - a.x) * p.y + b.x * a.y - b.y * a.x); x = x * x; y = (double(dist(a, b))); return x / y; } bool ascutit(punct a, punct b, punct c) { if (dist(a, b) + dist(b, c) > dist(a, c)) return true; return false; } int main() { cin >> n >> p.x >> p.y; for (i = 1; i <= n; i++) cin >> v[i].x >> v[i].y; if (inPoligon(v, n, p) == true) { long long x, mx; for (i = 1; i <= n; i++) { x = dist(v[i], p); if (x > mx) mx = x; } cout.fixed; cout << setprecision(7) << mx * 3.14159265359; } else { double x, mn = 2000000000000, mx = 0; v[n + 1] = v[1]; for (i = 1; i <= n; i++) { x = dist(v[i], p); if (x < mn) mn = x; if (x > mx) mx = x; if (ascutit(p, v[i], v[i + 1]) == true && ascutit(p, v[i + 1], v[i]) == true) { x = distD(v[i], v[i + 1], p); if (x < mn) mn = x; if (x > mx) mx = x; } } cout.fixed; cout << setprecision(15) << double(mx - mn) * 3.141592653589793238; } 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; struct Vector { double x, y; Vector() {} Vector(double x, double y) : x(x), y(y) {} Vector(const Vector& p1, const Vector& p2) : x(p2.x - p1.x), y(p2.y - p1.y) {} Vector(const Vector& p1, const Vector& p2, double t) : x(p1.x + t * p2.x), y(p1.y + t * p2.y) {} double norm() const { return hypot(x, y); } }; double dot(Vector p1, Vector p2) { return p1.x * p2.x + p1.y * p2.y; } double dist_pt_to_pt(Vector p1, Vector p2) { return Vector(p1, p2).norm(); } double dist_pt_to_segment(Vector p, Vector a, Vector b) { Vector u(a, p), v(a, b); double s = dot(u, v) / dot(v, v); if (s < 0 || s > 1) return min(dist_pt_to_pt(p, a), dist_pt_to_pt(p, b)); return dist_pt_to_pt(Vector(a, v, s), p); } int main() { int n, px, py; cin >> n >> px >> py; Vector p(px, py); vector<Vector> poly(n); for (int c = 0; c < n; c++) cin >> poly[c].x >> poly[c].y; double mr = 1e40, Mr = 0; for (int c = 0; c < n; c++) { mr = min(mr, dist_pt_to_segment(p, poly[c], poly[(c + 1) % n])); Mr = max(Mr, dist_pt_to_pt(p, poly[c])); } cout << fixed << setprecision(20); double pi = acos(-1); cout << pi * (Mr * Mr - mr * mr) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { if (a == 0) return b; return gcd(b % a, a); } template <typename T> T pow(T a, T b, long long m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } long double dist1(long double x1, long double y1, long double x2, long double y2) { return (long double)sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } long double dist2(long double x1, long double y1, long double x2, long double y2, long double x, long double y) { long double num = (y2 - y1) * x - (x2 - x1) * y + x2 * y1 - y2 * x1; long double den = dist1(x1, y1, x2, y2); num = abs(num); return (long double)num / den; } typedef struct node { long double x, y; } nd; bool func(long double x1, long double y1, long double x2, long double y2, long double x3, long double y3) { if (x3 > x1 && x3 > x2 || y3 > y1 && y3 > y2 || y3 < y1 && y3 < y2 || x3 < x1 && x3 < x2) return false; return true; } long double k(long double x1, long double y1, long double x2, long double y2, long double x3, long double y3) { long double ans = (y2 - y1) * (x3 - x1) - (x2 - x1) * (y3 - y1); long double den = (y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1); ans /= den; return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, x, y; cin >> n >> x >> y; vector<nd> v(n); for (long long i = 0; i < n; i++) { cin >> v[i].x >> v[i].y; } long double min1 = LLONG_MAX; long double max1 = 0; for (long long i = 0; i < n; i++) { long double dist = dist1(x, y, v[i].x, v[i].y); min1 = min(min1, dist); max1 = max(max1, dist); long double x1 = v[i].x; long double y1 = v[i].y; long double x2 = v[(i + 1) % n].x; long double y2 = v[(i + 1) % n].y; long double st = k(x1, y1, x2, y2, x, y); long double x4 = x - st * (y2 - y1); long double y4 = y + st * (x2 - x1); bool check = func(x1, y1, x2, y2, x4, y4); if (check) min1 = min(min1, dist2(v[i].x, v[i].y, v[(i + 1) % n].x, v[(i + 1) % n].y, x, y)); } cerr << "max1" << ": " << max1 << " | " << "min1" << ": " << min1 << "\n"; long double ans = 3.141592653589793 * (max1 * max1 - min1 * min1); cout << fixed << setprecision(12) << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 5; const unsigned long long MOD = (unsigned long long)1e8; const double PI = acos(-1.0); struct point { double x, y; point() {} point(double _x, double _y) { x = _x; y = _y; } point operator-(const point &b) const { return point(x - b.x, y - b.y); } double operator*(const point &b) const { return x * b.x + y * b.y; } } arr[MAXN]; struct line { point s, e; line() {} line(point _s, point _e) { s = _s; e = _e; } }; double dist(point a, point b) { return (a - b) * (a - b); } point neare(point P, line L) { point result; double t = (P - L.s) * (L.e - L.s) / ((L.e - L.s) * (L.e - L.s)); if (t >= 0 && t <= 1) { result.x = L.s.x + (L.e.x - L.s.x) * t; result.y = L.s.y + (L.e.y - L.s.y) * t; } else { if (dist(P, L.s) < dist(P, L.e)) { result = L.s; } else { result = L.e; } } return result; } int main() { int n; point P; while (scanf("%d%lf%lf", &n, &P.x, &P.y) != EOF) { double mi = 1e15, ma = 0.0; for (int i = 0; i < n; ++i) { scanf("%lf%lf", &arr[i].x, &arr[i].y); } for (int i = 0; i < n; ++i) { mi = min(mi, dist(neare(P, line(arr[i], arr[(i + 1) % n])), P)); ma = max(ma, dist(P, arr[i])); } printf("%.15lf\n", (ma - mi) * PI); } return 0; }
#include <bits/stdc++.h> using namespace std; class point { public: double x, y; point() {} point(double a, double b) { x = a; y = b; } double sqDis(point a) { return (x - a.x) * (x - a.x) + (y - a.y) * (y - a.y); } }; point c; double f1(point a, point b, int n) { if (n <= 0) return max(c.sqDis(a), c.sqDis(b)); point m((a.x + b.x) / 2, (a.y + b.y) / 2); double r1 = c.sqDis(a); double r2 = c.sqDis(b); if (r1 > r2) return f1(a, m, n - 1); return f1(m, b, n - 1); } double f2(point a, point b, int n) { if (n <= 0) return min(c.sqDis(a), c.sqDis(b)); point m((a.x + b.x) / 2, (a.y + b.y) / 2); double r1 = c.sqDis(a); double r2 = c.sqDis(b); if (r1 < r2) return f2(a, m, n - 1); return f2(m, b, n - 1); } int main() { int n; cin >> n >> c.x >> c.y; point a[n]; for (int i = 0; i < n; i++) { cin >> a[i].x >> a[i].y; } double r = f1(a[0], a[n - 1], 10); for (int i = 0; i < n - 1; i++) { r = max(r, f1(a[i], a[i + 1], 10)); } double r1 = f2(a[0], a[n - 1], 10); for (int i = 0; i < n - 1; i++) { r1 = min(r1, f2(a[i], a[i + 1], 10)); } printf("%.10lf", 3.1415926536 * (r - r1)); return 0; }
#include <bits/stdc++.h> const double PI = 3.141592653589793; using namespace std; long long rast(long long x, long long y, long long x0, long long y0) { return (x - x0) * (x - x0) + (y - y0) * (y - y0); } long long ax[100500]; long long ay[100500]; int main() { int n; long long x0, y0; cin >> n >> x0 >> y0; long long maxx = 0, minn = 2000000000000000000ll; long long oldx = -1, oldy = -1; for (int(i) = 0; (i) < (n); (i)++) { long long x, y; cin >> x >> y; maxx = max(maxx, (x - x0) * (x - x0) + (y - y0) * (y - y0)); minn = min(minn, (x - x0) * (x - x0) + (y - y0) * (y - y0)); ax[i] = x; ay[i] = y; } double minn2 = double(minn); for (int(i) = 0; (i) < (n); (i)++) { oldx = (ax[(i + 1) % n]); oldy = (ay[(i + 1) % n]); long long ab = rast(ax[i], ay[i], oldx, oldy); long long bc = rast(ax[i], ay[i], x0, y0); long long ac = rast(oldx, oldy, x0, y0); double sab = sqrt(double(ab)), sbc = sqrt(double(bc)), sac = sqrt(double(ac)); double p = (sab + sbc + sac) / 2; if (ab + bc - ac > 0 && ab + ac - bc > 0) { minn2 = min(minn2, 4. / double(ab) * p * (p - sab) * (p - sac) * (p - sbc)); } } printf("%.7f", PI * (double(maxx) - minn2)); return 0; }
#include <bits/stdc++.h> using namespace std; const long double pi = acos(-1.0); struct point { long double x; long double y; long double nextx; long double nexty; }; point o; long double dissquare(point b) { return (o.x - b.x) * (o.x - b.x) + (o.y - b.y) * (o.y - b.y); } bool cmp(point c, point d) { return dissquare(c) < dissquare(d); } point a[100010]; int main() { int n; scanf("%d%llf%llf", &n, &o.x, &o.y); for (int i = 0; i < n; i++) { scanf("%llf%llf", &a[i].x, &a[i].y); } long double line = 999999999999999999; if (a[0].x != a[n - 1].x) { long double detx = a[0].x - a[n - 1].x; long double dety = a[0].y - a[n - 1].y; long double b = (a[0].x * a[n - 1].y - a[0].y * a[n - 1].x) / (a[0].x - a[n - 1].x); long double xx = (o.x * detx * detx + o.y * detx * dety - b * detx * dety) / (dety * dety + detx * detx); if (xx >= min(a[0].x, a[n - 1].x) && xx <= max(a[0].x, a[n - 1].x)) { line = min( line, ((a[n - 1].y - a[0].y) * o.x - (a[n - 1].x - a[0].x) * o.y + a[0].y * a[n - 1].x - a[0].x * a[n - 1].y) * ((a[n - 1].y - a[0].y) * o.x - (a[n - 1].x - a[0].x) * o.y + a[0].y * a[n - 1].x - a[0].x * a[n - 1].y) / ((a[n - 1].y - a[0].y) * (a[n - 1].y - a[0].y) + (a[n - 1].x - a[0].x) * (a[n - 1].x - a[0].x))); } } else { if (o.y <= max(a[0].y, a[n - 1].y) && o.y >= min(a[0].y, a[n - 1].y)) { line = min(line, (o.x - a[0].x) * (o.x - a[0].x)); } } int cnt = 0; for (int i = 0; i < n; i++) { if (i != n - 1) { if (a[i].x != a[i + 1].x) { long double detx = a[i].x - a[i + 1].x; long double dety = a[i].y - a[i + 1].y; long double b = (a[i].x * a[i + 1].y - a[i].y * a[i + 1].x) / (a[i].x - a[i + 1].x); long double xx = (o.x * detx * detx + o.y * detx * dety - b * detx * dety) / (dety * dety + detx * detx); if (xx >= min(a[i].x, a[i + 1].x) && xx <= max(a[i].x, a[i + 1].x)) { line = min( line, ((a[i + 1].y - a[i].y) * o.x - (a[i + 1].x - a[i].x) * o.y + a[i].y * a[i + 1].x - a[i].x * a[i + 1].y) * ((a[i + 1].y - a[i].y) * o.x - (a[i + 1].x - a[i].x) * o.y + a[i].y * a[i + 1].x - a[i].x * a[i + 1].y) / ((a[i + 1].y - a[i].y) * (a[i + 1].y - a[i].y) + (a[i + 1].x - a[i].x) * (a[i + 1].x - a[i].x))); } } else { if (o.y <= max(a[i].y, a[i + 1].y) && o.y >= min(a[i].y, a[i + 1].y)) { line = min(line, (o.x - a[i].x) * (o.x - a[i].x)); } } } } sort(a, a + n, cmp); if (line != 999999999999999999) { long double ans = pi * (dissquare(a[n - 1]) - min(dissquare(a[0]), line)); cout << fixed << setprecision(18) << ans << endl; } else { cout << fixed << setprecision(18) << pi * (dissquare(a[n - 1]) - dissquare(a[0])) << endl; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; mt19937 gen; struct point { long long x, y; } x[100010]; struct vect { long long x, y; vect(point a, point b) : x(b.x - a.x), y(b.y - a.y){}; }; long double dist(point a, point b) { return sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y)); } long long scalmul(vect a, vect b) { return a.x * b.x + a.y * b.y; } long long vectmul(vect a, vect b) { return (a.x * b.y - a.y * b.x); } vector<long double> d; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20); int n; point p; cin >> n >> p.x >> p.y; for (int i = 0; i < n; ++i) { cin >> x[i].x >> x[i].y; d.push_back(dist(x[i], p)); } x[n] = x[0]; for (int i = 0; i < n; ++i) { if (scalmul(vect(p, x[i]), vect(x[i + 1], x[i])) >= 0 && scalmul(vect(p, x[i + 1]), vect(x[i], x[i + 1])) >= 0) d.push_back(abs(vectmul(vect(p, x[i]), vect(x[i], x[i + 1]))) / 1. / dist(x[i], x[i + 1])); } sort((d).begin(), (d).end()); long double ans = 3.1415926535897932384626433832795 * (d.back() * d.back() - d[0] * d[0]); cout << ans; cerr << "\nTime Elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms"; }
#include <bits/stdc++.h> using namespace std; struct node { double x, y; } o, p[111111]; int n; 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 A = dis(b, c), B = dis(a, c), C = dis(a, b); if (A * A + C * C <= B * B) return A; if (B * B + C * C <= A * A) return B; double s = abs((a.x - c.x) * (b.y - c.y) - (a.y - c.y) * (b.x - c.x)); return s / dis(a, b); } int main() { while (~scanf("%d%lf%lf", &n, &o.x, &o.y)) { double Min = 0x7f7f7f7f7f, Max = 0; for (int i = 0; i < n; i++) { scanf("%lf%lf", &p[i].x, &p[i].y); double temp = dis(p[i], o); Max = max(Max, temp); } for (int i = 0; i < n; i++) { int j = (i + 1) % n; Min = min(Min, get_dis(p[i], p[j], o)); } printf("%.10lf\n", (Max * Max - Min * Min) * acos(-1.0)); } return 0; }
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const double pi = acos(-1.0); int sgn(double x) { if (fabs(x) < 0) return 0; if (x < 0) return -1; else return 1; } struct point { double x, y; point() {} point(double xx, double yy) { x = xx; y = yy; } point operator-(const point &b) const { return point(x - b.x, y - b.y); } double operator^(const point &b) const { return x * b.y - y - b.x; } double operator*(const point &b) const { return x * b.x + y * b.y; } int len2() { return (*this) ^ (*this); } }; struct line { point s, e; line() {} line(point ss, point ee) { s = ss; e = ee; } }; point p[100003]; double dist(point a, point b) { return sqrt((a - b) * (a - b)); } point lenth(point a, point b, point c) { point res; double t = ((a - b) * (c - b)) / ((c - b) * (c - b)); if (t >= 0 && t <= 1) { res.x = b.x + (c.x - b.x) * t; res.y = b.y + (c.y - b.y) * t; } else { if (dist(a, b) < dist(a, c)) res = b; else res = c; } return res; } int main() { int n; point q; scanf("%d%lf%lf", &n, &q.x, &q.y); double maxm = 0, minm = 100000000; for (int i = 0; i < n; i++) { scanf("%lf%lf", &p[i].x, &p[i].y); maxm = max(maxm, dist(p[i], q)); } for (int i = 0; i < n; i++) { point tp; tp = lenth(q, p[i], p[(i + 1) % n]); double x = dist(q, tp); minm = min(minm, x); } double s = pi * (maxm * maxm - minm * minm); printf("%.8f\n", s); return 0; }
#include <bits/stdc++.h> using namespace std; long double pointLineDist(const complex<long double>& a, const complex<long double>& b, const complex<long double>& p) { return fabs(((conj(((b) - (a))) * (((p) - (a)))).imag()) / ((long double)hypot((((b) - (a))).imag(), (((b) - (a))).real()))); } long double pointSegmentDist(const complex<long double>& a, const complex<long double>& b, const complex<long double>& p) { if (((conj(((b) - (a))) * (((p) - (a)))).real()) < 1e-9) return ((long double)hypot((((p) - (a))).imag(), (((p) - (a))).real())); if (((conj(((a) - (b))) * (((p) - (b)))).real()) < 1e-9) return ((long double)hypot((((p) - (b))).imag(), (((p) - (b))).real())); return pointLineDist(a, b, p); } int main() { vector<complex<long double> > v; int n, k, l1, f, s; cin >> n >> k >> l1; complex<long double> b = complex<long double>(k, l1); long double mx = -1, mn = 10000000; for (int i = 0; i < n; i++) { cin >> f >> s; complex<long double> a = complex<long double>(f, s); mx = max(mx, ((long double)hypot((a - b).imag(), (a - b).real()))); v.push_back(complex<long double>(f, s)); } for (int i = 0; i < n; i++) { mn = min(mn, pointSegmentDist(v[i], v[(i + 1) % n], b)); } cout << setprecision(15) << (long double)atan(1) * 4 * (mx * mx - mn * mn); return 0; }
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int MOD = 1e9 + 7; const long long INF = 1e15 + 9; const int MX = 1e5 + 5; double pointX, pointY; double FindDistanceToSegment(double x1, double y1, double x2, double y2) { double diffX = x2 - x1; double diffY = y2 - y1; if ((diffX == 0) && (diffY == 0)) { diffX = pointX - x1; diffY = pointY - y1; return 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 n; double px, py; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); ; cout << setprecision(18) << fixed; ; cin >> n; cin >> px >> py; pointX = px; pointY = py; double ma, mi; ma = -1 * 1.0 * INF; mi = 1.0 * INF; double fx, fy, prex, prey, x, y, r; cin >> fx >> fy; prex = fx; prey = fy; r = fabs(fx - px) * fabs(fx - px) + fabs(fy - py) * fabs(fy - py); ma = max(ma, r); mi = min(mi, r); for (int i = 1; i < n; i++) { cin >> x >> y; r = FindDistanceToSegment(prex, prey, x, y); ma = max(ma, r); mi = min(mi, r); r = fabs(x - px) * fabs(x - px) + fabs(y - py) * fabs(y - py); ma = max(ma, r); mi = min(mi, r); prex = x; prey = y; } r = FindDistanceToSegment(fx, fy, x, y); ma = max(ma, r); mi = min(mi, r); double ans; ans = PI * (ma - mi); cout << ans << endl; return 0; }