#include<bits/stdc++.h> constexprint N = 2e5 + 10; constexprint V = 1e9, M = 2e5; using ll = longlong;
ll n, a[N], b[N];
voidgen(){ std::mt19937 rng(std::random_device{}()); n = rng() % M + 1; longlong sum = 0; for (int i = 1; i <= n; i++) b[i] = rng() % V + 1, sum += b[i]; for (int i = 1; i <= n; i++) a[i] = std::round(1.0L * b[i] / sum * 100.0); std::cerr << n << "\n"; for (int i = 1; i <= n; i++) std::cerr << a[i] << " \n"[i == n]; }
voidrun(){ // gen(); std::cin >> n; int low = 0, high = 0; ll sum = 0;
for (int i = 1; i <= n; i++) { std::cin >> a[i]; b[i] = 0; low += a[i] == 0 ? 0 : 1; sum += a[i]; high += a[i] == 100 ? 0 : 1; }
if (!(sum * 2 - low <= 200 && 200 < sum * 2 + high || (sum == 100))) { std::cout << "No\n"; return; } std::cout << "Yes\n"; sum -= 100; ll t = -2 * sum;
if (sum > 0) { sum *= 2; for (int i = 1; i <= n && sum > 0; i++) if (a[i] >= 1) { b[i] = 1; sum--; } } else { sum = -2 * sum; int i = 1; for (; i <= n && sum > 0; i++) { if (a[i] < 100) { b[i] = -1; sum--; } } bool put = false; for (; i <= n; i++) { if (a[i] < 100) { b[i] = -2; put = true; break; } } } assert(sum == 0);
ll base = 1000000, ssum = 0; for (int i = 1; i <= n; i++) { if (b[i] == 0) b[i] = a[i] * base; elseif (b[i] > 0) b[i] = a[i] * base - 500000; elseif (b[i] == -1) b[i] = a[i] * base + 499999; elseif (b[i] == -2) b[i] = a[i] * base + t; ssum += b[i]; }
for (int i = 1; i <= n; i++) { std::cout << b[i] << " \n"[i == n]; } }
intmain(){ int t = 1; std::cin >> t; while (t--) run(); }
#include<bits/stdc++.h> using ll = longlong; constexprint N = 6, M = 1 << N; constexpr ll inf = 1e18;
int n, m, k, r, a[N], c[N]; int state;
structMat : public std::array<std::array<ll, M>, M> { Mat() { clear(0); } Mat(ll val) { clear(val); } voidclear(ll val){ for (int i = 0; i < state; i++) for (int j = 0; j < state; j++) at(i).at(j) = val; } Mat operator*(Mat &rhs) { Mat res(-inf);
for (int i = 0; i < state; i++) for (int j = 0; j < state; j++) for (int k = 0; k < state; k++) res[i][j] = std::max(res[i][j], (*this)[i][k] + rhs[k][j]);
return res; }
voiddebug()const{ for (int i = 0; i < state; i++) { for (int j = 0; j < state; j++) { if (at(i).at(j) == -inf) std::cout << std::setw(5) << "-inf"; else std::cout << std::setw(5) << at(i).at(j); } std::cout << "\n"; } } };
ll assign(int m1, int m2){ int totcost = 0; ll atk = 0; for (int i = 0; i < n; i++) { if (m2 >> i & 1) { atk += a[i]; totcost += c[i]; m1 >> i & 1 ? totcost += k : 0; } }
return totcost <= m ? atk : -inf; }
voidrun(){ std::cin >> n >> m >> k >> r; state = 1 << n; for (int i = 0; i < n; i++) std::cin >> a[i] >> c[i];
Mat x(-inf); for (int i = 0; i < state; i++) for (int j = 0; j < state; j++) x[i][j] = assign(i, j); // x.debug();
Mat res(0); while (r) { if (r & 1) res = res * x; x = x * x; r >>= 1; }
ll ans = 0; for (int i = 0; i < state; i++) for (int j = 0; j < state; j++) ans = std::max(ans, res[i][j]);
std::cout << ans << "\n"; }
intmain(){ std::cin.tie(0)->sync_with_stdio(0), std::cout.tie(0); int t; std::cin >> t; while (t--) run(); }
简单的模拟题,先计算一开始有哪些 paper 过了(记为 a),只保留没有过的 paper 然后对于每张 paper 计算 rebuttal 后的新分数,判断 rebuttal 后有多少 paper 可以过. 假设有 f 张,因为最多 rebuttal b 张 paper,所以答案就是 a+min(f,b)
#include<bits/stdc++.h> constexprint N = 2e5 + 10;
int n, a[N], b[N], ans[N]; int L[N], R[N], stamp, size[N], son[N], ord[N], dfn[N]; std::vector<int> g[N]; int remainA{0}, remainB{0}; int cnta[N], cntb[N];
voidclean(){ for (int i = 0; i <= n; i++) cnta[i] = cntb[i] = 0; for (int i = 1; i <= n; i++) { g[i].clear(), ans[i] = 0; L[i] = R[i] = 0; size[i] = 0; son[i] = 0; } stamp = 0; remainA = remainB = 0; }
voiddfs(int u, int fa){ dfn[u] = ++stamp; ord[stamp] = u; L[u] = dfn[u]; size[u] = 1;
for (auto v : g[u]) { if (v == fa) continue; dfs(v, u); size[u] += size[v]; if (size[v] > size[son[u]]) son[u] = v; }
R[u] = stamp; }
voidmodify(int *x, int val, int v = 1){ if (val == 0) { x[val] += v; return; }
voidcompute(int u, int fa, bool keep){ for (auto v : g[u]) { if (v == fa or v == son[u]) continue; compute(v, u, false); }
if (son[u]) compute(son[u], u, true);
for (auto v : g[u]) { if (v == fa or v == son[u]) continue; for (int i = L[v]; i <= R[v]; i++) add(ord[i]); } add(u); ans[u] = getans();
if (!keep) for (int i = L[u]; i <= R[u]; i++) del(ord[i]); }
voidrun(){ std::cin >> n; clean();
for (int i = 1; i <= n; i++) std::cin >> a[i]; for (int i = 1; i <= n; i++) std::cin >> b[i]; for (int i = 1, u, v; i < n; i++) { std::cin >> u >> v; g[u].push_back(v), g[v].push_back(u); }
dfs(1, 0); compute(1, 0, true);
for (int i = 1; i <= n; i++) std::cout << ans[i]; std::cout << "\n"; }
intmain(){ std::cin.tie(0)->sync_with_stdio(0), std::cout.tie(0); int t; std::cin >> t; while (t--) run(); }