constint N = 1e5 + 5; int x[N], v[N], l[N], r[N]; bitset<N> dead;
ldouble solve(int i, int j){ if (v[i] == v[j]) return-1; ldouble dx = x[j] - x[i], dv = v[i] - v[j]; return dx / dv; }
signedmain(){ #ifndef ONLINE_JUDGE freopen("/home/nanami/CLionProjects/untitled/input.txt", "r", stdin); #endif int n = read(); for (int i = 1; i <= n; ++ i) x[i] = read(), v[i] = read(); for (int i = 2; i < n; ++ i) l[i] = i - 1, r[i] = i + 1; l[1] = r[n] = -1, r[1] = 2, l[n] = n - 1; priority_queue<tuple<ldouble, int, int>> heap; for (int i = 1; i < n; ++ i) { if (v[i] != v[i + 1]) { auto t = solve(i, i + 1); if (t > 0) heap.emplace(-t, i, i + 1); } } while (!heap.empty()) { auto [_t, ll, rr] = heap.top(); heap.pop(); if (dead[ll] || dead[rr]) continue; dead.set(ll), dead.set(rr); auto nl = l[ll], nr = r[rr]; if (nl < 0 || nr < 0) continue; else r[nl] = nr, l[nr] = nl; if (v[nl] != v[nr]) { auto nt = solve(nl, nr); if (nt > 0) heap.emplace(-nt, nl, nr); } } auto ans = n - dead.count(); cout << ans << endl; for (int i = 1; i <= n; ++ i) if (!dead[i]) cout << i << ' '; cout << endl; return0; }
constint N = 110, M = 12315; llong a[N], f[M], inf = 1e18;
boolcompare(int i, int j){ auto ii = a[i] * j, jj = a[j] * i; if (ii == jj) return i < j; elsereturn ii < jj; }
signedmain(){ int n = read(), q = read(), _[N]; for (int i = 1; i <= n; ++ i) a[i] = read(); iota(_, _ + n, 1); auto m = *min_element(_, _ + n, compare); auto lim = (m + 1) * n; fill(f + 1, f + 1 + lim, inf); memcpy(f + 1, a + 1, sizeof(llong) * n); for (int i = n + 1; i <= lim; ++ i) for (int j = 1; j <= n; ++ j) f[i] = min(f[i], f[i - j] + a[j]); while (q --) { int x = read(); if (x <= lim) printf("%lld\n", f[x]); else { int t = (x - lim + m - 1) / m; int mt = m * t, res = x - mt; printf("%lld\n", f[res] + a[m] * t); } } return0; }
其实完全没有必要想这么多;因为著名的 \(x \cdot y - x - y\) 问题(大概是这个式子吧,不排除我记错了的可能)我们都有常识:使用一些正整数组成更大的正整数,在某个边界之后可以组成任何正整数;虽然不完全一样,但是这并不影响我们想到上面的猜想;至于这个边界,去取一个足够大但是又时间足够求出的范围就完全没问题()就算再蠢想不到贪心 \(m\),检查所有的元素作为首要替代也可以通过此题…… 只能说确实拉了==
voidclear(int n){ for (int i = 1; i <= n; ++ i) ta[i].clear(); }
booltest(coord S, coord T, int n){ if (S == T) returntrue; for (int i = 1; i <= n; ++ i) { auto t = S + d[i]; if (t == T) returntrue; if (valid(t.x, t.y)) ta[t.x].insert(t.y); } for (int i = 1; i <= n; ++ i) { auto t = T - d[i]; if (valid(t.x, t.y) && ta[t.x].count(t.y)) returntrue; } returnfalse; }
coord gen(const function<int()>& rand_int){ int x = rand_int(), y = rand_int(); while (vis[x].count(y)) x = rand_int(), y = rand_int(); return {x, y}; }
signedmain(){ int n = read(); a.x = read(), a.y = read(); b.x = read(), b.y = read(); for (int i = 1; i <= n; ++ i) d[i].x = read(), d[i].y = read(); if (test(a, b, n)) puts("Alice wins"); elseif (n <= 10) { for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) { auto t = coord(i, j); if (t != a && t != b) { clear(n); auto res = test(b, t, n); if (!res) { printf("tie %d %d\n", t.x, t.y); return0; } } } puts("Bob wins"); } else { vis[b.x].insert(b.y); constauto rd = createRandomMachine(1, n + 1); for (int tt = 100; tt; -- tt) { auto t = gen(rd); vis[t.x].insert(t.y), clear(n); auto res = test(b, t, n); if (!res) { printf("tie %d %d\n", t.x, t.y); return0; } } puts("Bob wins"); } return0; }
boolsimulator(constint *it, constint *jt, int i0, int j0, int n){ if (i0 == j0) returntrue; int i = i0, j = j0; llong il = 0, jl = 0, ir, jr; calcR(i), calcR(j); for (int t = 0; t < n; ++ t) { assign(i), assign(j), calcL(i), calcL(j); i = step(i), j = step(j), calcR(i), calcR(j); } for (int x = 1; x <= n; ++ x) if (iil[x] < jjr[x] && jjl[x] < iir[x]) returntrue; returnfalse; }
signedmain(){ int n = read(); for (int i = 1; i <= n; ++ i) d[i] = read(); for (int i = 1; i <= n; ++ i) a[i] = read(); for (int i = 1; i <= n; ++ i) b[i] = read(); for (int i = 1; i <= n; ++ i) c[i] = read(); for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) { ab[i][j] = simulator(a, b, i, j, n); ac[i][j] = simulator(a, c, i, j, n); bc[i][j] = simulator(b, c, i, j, n); } for (int i = 1; i <= n; ++ i) for (int j = 1; j <= n; ++ j) for (int k = 1; k <= n; ++ k) if (!(ab[i][j] || ac[i][k] || bc[j][k])) returnprintf("%d %d %d\n", i, j, k), 0; puts("impossible"); return0; }
voidadd_edge(int u, int v){ edge tmp(v, head[u]); head[u] = (int) e.size(); e.emplace_back(move(tmp)); } } g;
voiddfs(int u){ if (!vis[u] && A != B) { belong[u] = 0; path.push_back(u); -- A; } vis[u] = true; for (int i = g.head[u]; i >= 0; i = g.e[i].second) { int v = g.e[i].first; if (vis[v]) continue; dfs(v); if (A != B) { path.pop_back(); belong[v] = -1; ++ B; } } }
signedmain(){ int n = read(), m = read(); g.renew(n + 1), g.e.reserve(m * 2 + 5); for (int i = m; i --;) { int u = read(), v = read(); g.add_edge(u, v); g.add_edge(v, u); } fill(belong, belong + 1 + n, 1); A = n, B = 0, dfs(1); vector<int> aa, bb; for (int i = 1; i <= n; ++ i) if (belong[i] < 0) bb.push_back(i); elseif (belong[i]) aa.push_back(i); cout << path.size() << ' ' << A << endl; for (auto i : path) cout << i << ' '; cout << endl; for (auto i : aa) cout << i << ' '; cout << endl; for (auto i : bb) cout << i << ' '; cout << endl; return0; }