vector<vector<int>> adj(n); for (int x = 0; x < n; x++) { for (int _ = 0; _ < 2; _++) { int y; cin >> y; if (y == 0) continue; y--; adj[x].push_back(y); adj[y].push_back(x); } }
int s = 0; while (1) { // 找重心 begin vector<int> siz(n, 1); [&](thisauto&& self, int x, int p = -1) -> void { for (constauto& y : adj[x]) { if (y == p) { continue; } self(y, x); siz[x] += siz[y]; } } (s);
vector<int> mss(n); [&](thisauto&& self, int x, int p = -1) -> void { for (constauto& y : adj[x]) { if (y == p) { continue; } self(y, x); mss[x] = max(mss[x], siz[y]); } mss[x] = max(mss[x], siz[s] - siz[x]); } (s);
int ctr = [&](thisauto&& self, int x, int p = -1) -> int { for (constauto& y : adj[x]) { if (y == p || 2 * siz[y] <= siz[s]) { continue; } returnself(y, x); } return x; } (s); // 找重心 end
if (adj[ctr].empty()) { answer(ctr); break; } elseif (adj[ctr].size() == 1) { int x = ctr, y = adj[ctr][0]; int res = query(x, y); if (res == 0) { // d(x) < d(y) answer(x); break; } else { // d(x) > d(y) answer(y); break; } } else { ranges::sort(adj[ctr], {}, [&](int x) { return mss[x]; }); int x = adj[ctr][0], y = adj[ctr][1]; int res = query(x, y); if (res == 0) { // d(x) < d(y) s = x; adj[s].erase(ranges::find(adj[s], ctr)); } elseif (res == 2) { // d(x) > d(y) s = y; adj[s].erase(ranges::find(adj[s], ctr)); } else { // d(x) == d(y) s = ctr; adj[s].erase(adj[s].begin()); adj[s].erase(adj[s].begin()); } } } }
vector<int> a(N * M + 1); for (int i = 1; i <= N * M; i++) { cin >> a[i]; } sort(a.begin(), a.end());
vector<Z> f(N * M + 1); vector<Z> g(N * M + 1); for (int i = 1; i <= N * M; i++) { f[i] = a[i] * fac[i - 1]; } for (int i = 0; i <= N * M; i++) { g[i] = invfac[N * M - i]; } auto h = f * g;
Z res = 0; for (int n = 0; n <= N; n++) { for (int m = 0; m <= M; m++) { int c = M * n + N * m - n * m; res += (n + m & 1 ? 1 : -1) * binom(N, n) * binom(M, m) * c * fac[N * M - c] * h[N * M + c]; } } cout << res << endl; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong; const ll N = 2e5 + 10; const ll inf = 1e18;
voideachT() { int n, m, k, w; cin >> n >> m >> k >> w; vector<int> a(n), b(m + 2); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (int i = 1; i <= m; i++) { cin >> b[i]; } b[0] = 0; b[m + 1] = w + 1; sort(b.begin(), b.end());
bool ok = 1; vector<int> res;
auto solve = [&](vector<ll>& a, int& l, int& r) -> void { vector<int> pos; int len = a.size(); for (int i = 0; i < len; ) { pos.push_back(a[i] + k - 1); int p = upper_bound(a.begin(), a.end(), a[i] + k - 1) - a.begin(); if (a[p] == r) { for (auto x : pos) { res.push_back(x - k + 1); } return; } elseif (a[p] == inf) { pos[pos.size() - 1] = r - 1; for (int j = pos.size() - 1; j >= 0; j--) { if (pos[j] - k + 1 <= l) { ok = 0; return; } if (j >= 1 && pos[j] - k + 1 <= pos[j - 1]) { pos[j - 1] = pos[j] - k; } else { for (auto x : pos) { res.push_back(x - k + 1); } return; } } } else { i = p; } } };
int now = 1; vector<ll> aa; for (int i = 0; i < n;) { if (!ok) { break; } while (a[i] > b[now]) { now++; } while (a[i] <= b[now]) { aa.push_back(a[i]); i++; if (i >= n) { break; } } aa.push_back(b[now]); aa.push_back(inf); solve(aa, b[now - 1], b[now]); aa.clear(); now++; } if (!ok) { cout << -1 << endl; } else { cout << res.size() << endl; for (auto x : res) { cout << x << " "; } cout << endl; }
using numbers::pi; // acos(-1.0) using Point = complex<double>;
intmain(){ cout << fixed << setprecision(15); int N, x, y, Rad, T; cin >> N >> x >> y >> Rad >> T;
Point P0 = Point(x, y); double t0 = arg(P0);
vector<double> alpha; alpha.reserve(2 * N); for (int i = 0; i < N; i++) { int x, y; cin >> x >> y; Point Q = Point(x, y); double phi = acos(Rad / abs(Q)); // 切点 - 原点 - 多边形顶点 形成的角度 // 切点的角 arg(Q) + phi // 切点 H = polar(Rad, arg(Q) + phi) // 切点 - 多边形顶点 向量 Q - H // 这个向量的倾斜角 arg() 即是所求 alpha.push_back(arg(Q - polar((double)Rad, (arg(Q) + phi)))); // 另外一边的切线同理 alpha.push_back(arg(Q - polar((double)Rad, (arg(Q) - phi)))); } // 减去初始角度 for (int i = 0; i < 2 * N; i++) { alpha[i] -= t0; if (alpha[i] < 0) alpha[i] += 2 * pi; } ranges::sort(alpha);
double lo = -1, hi = -1; bool flag = 1; if (alpha[0] + pi > alpha.back()) { lo = alpha[0], hi = alpha.back(); flag = 0; } elsefor (int i = 1; i < 2 * N; i++) { if (alpha[i - 1] + pi < alpha[i]) { lo = alpha[i - 1], hi = alpha[i]; } }
double r = fmod(T, (2 * pi)); // remainder double q = (T - r) / (2 * pi); // quotient double res = q * (hi - lo); // full circles if (r > lo) res += r - lo; if (r > hi) res -= r - hi; // partial circle
if (flag) { cout << T - res << endl; } else { cout << res << endl; }