voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int a, b; cin >> a >> b; bool flag = false; if (a % 2 == 0) { int ra = a / 2, rb = b * 2; if (ra != b || rb != a) flag = true; } if (b % 2 == 0) { int ra = a * 2, rb = b / 2; if (ra != b || rb != a) flag = true; } cout << (flag ? "YES" : "No") << endl; } }
B. Equalize
大致题意
已知一个数组,现在将一个等长的排列加到这个数组上,问最多出现多少个相同的值
思路
等价于在长度为 $n$ 的值范围内,原始数组有多少个不同的值
AC code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n; cin >> n; vector<int> data(n); for (auto& i: data) cin >> i; sort(data.begin(), data.end()); int end = (int)(unique(data.begin(), data.end()) - data.begin()); int l = 0, ans = 0; for (int r = 0; r < end; ++r) { while (data[r] - data[l] >= n) ++l; ans = max(ans, r - l + 1); } cout << ans << endl; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int x, n, v[2]; cin >> x >> n; // upside v[0] = x - n; // downside v[1] = x + n - 2; set<int> st;
auto add = [&](int x) { if (x % 2 || x < n * 2 - 2) return; st.insert(x); }; auto cal = [&](int x) { int r = min((int)sqrt(x) + 10, x); for (int i = 1; i < r; ++i) if (x % i == 0) { add(i); add(x / i); } };
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n, b, x; cin >> n >> b >> x; vector<int> c(n); for (auto &i: c) cin >> i; int l = 1, r = 2e5 + 10;
auto check = [&](int mid) { int res = -x * (mid - 1); for (constauto &i: c) { int v = i / mid, c1 = i % mid, c2 = mid - c1; res += b * c1 * (v + 1) * (i - v - 1) / 2; res += b * c2 * v * (i - v) / 2; } return res; };
while (l + 10 < r) { int ml = (2 * l + r) / 3, mr = (l + 2 * r) / 3; int rl = check(ml), rr = check(mr); if (rl < rr) l = ml; else r = mr; }
int ans = 0; for (int i = l; i <= r; ++i) ans = max(ans, check(i)); cout << ans << endl; } }
voidsolve(){ int _; cin >> _; for (int tc = 0; tc < _; ++tc) { int n, x, y, s; cin >> n >> x >> y >> s;
if ((s - n * (x % y)) % y || (x % y) * n > s || x > s) { cout << "NO" << endl; continue; } int rs = (s - n * (x % y)) / y; int st = x / y - 1; if (x / y > rs) { cout << "NO" << endl; continue; }
vector<pair<int, int>> dp(rs + 1, {0x3fffffff, -1}); dp[rs] = {0, -1}; for (int i = st + 1, tmp = 0; i <= s; ++i) { tmp += i; if (tmp == 0) continue; if (rs - tmp < 0) break; dp[rs - tmp] = {i, rs}; } for (int i = rs - 1; i >= 1; --i) for (int j = 1; j < 623; ++j) { if (i - (1 + j) * j / 2 < 0) break; if (dp[i - (1 + j) * j / 2].first <= dp[i].first + j + 1) continue; dp[i - (1 + j) * j / 2] = {dp[i].first + j + 1, i}; } if (st + n < dp[0].first) { cout << "NO" << endl; continue; } cout << "YES" << endl; int cur = 0; vector<int> res; while (~cur) { if (dp[cur].second != -1) res.push_back(dp[cur].second - cur); cur = dp[cur].second; if (res.size() > 100) { cerr << 1; } } reverse(res.begin(), res.end()); int index = 0; for (int i = 0; i < res.size(); ++i) { int cost = 0, j = i == 0 ? st + 1 : 0; while (cost <= res[i]) { cout << j * y + x % y << ' '; ++index; ++j; cost += j; } } while (index < n) { cout << x % y << ' '; ++index; } cout << endl; } }