比赛链接:Here


1546A - AquaMoon and Two Arrays

选定两个数组元素执行以下操作:

  • Codeforces Round #732 (Div. 2) 思维场 - 图1#card=math&code=a_i%2Ca_j%20%281%5Cle%20i%2Cj%20%5Cle%20n%29) 一个 +1 另一个 -1,
    前提是两个数都要结果非负

请问在执行若干次后使得数组 Codeforces Round #732 (Div. 2) 思维场 - 图2 等于 数组 Codeforces Round #732 (Div. 2) 思维场 - 图3


先统计两个数组总和,只有和相同可以,否则输出 -1

  1. int main() {
  2. cin.tie(nullptr)->sync_with_stdio(false);
  3. int _; for (cin >> _; _--;) {
  4. int n; cin >> n;
  5. int suma = 0, sumb = 0;
  6. vector<int>a(n), b(n);
  7. for (int &x : a)cin >> x, suma += x;
  8. for (int &x : b)cin >> x, sumb += x;
  9. if (suma != sumb) {
  10. cout << "-1\n";
  11. continue;
  12. }
  13. int cnt = 0;
  14. vector<pair<int, int>>ans;
  15. for (int i = 0; i < n; ++i)
  16. if (a[i] > b[i])ans.push_back({i, a[i] - b[i]}), cnt += (a[i] - b[i]);
  17. cout << cnt << "\n";
  18. if (cnt == 0)continue;
  19. int j = 0;
  20. for (int i = 0; i < n; ++i) {
  21. while (a[i] < b[i]) {
  22. if (ans[j].second > 0) {
  23. a[i]++;
  24. cout << ans[j].first + 1 << " " << i + 1 << "\n";
  25. ans[j].second--;
  26. } else j++;
  27. }
  28. }
  29. }
  30. }

1546B - AquaMoon and Stolen String

题意都能看懂就不写了…


在每一列中,只会有一个元素出现奇数次,

只需要 map 存第 Codeforces Round #732 (Div. 2) 思维场 - 图4 位的值即可

  1. int main() {
  2. cin.tie(nullptr)->sync_with_stdio(false);
  3. int _; for (cin >> _; _--;) {
  4. int n, m;
  5. cin >> n >> m;
  6. vector<ll>v(m, 0);
  7. string s;
  8. for (int i = 0; i < n; ++i) {
  9. cin >> s;
  10. for (int j = 0 ; j < m; ++j)
  11. v[j] += (s[j] - 'a');
  12. }
  13. for (int i = 0; i < n - 1; ++i) {
  14. cin >> s;
  15. for (int j = 0; j < m; ++j)
  16. v[j] -= (s[j] - 'a');
  17. }
  18. for (int i = 0; i < m; ++i) cout << char(v[i] + 'a');
  19. cout << '\n';
  20. }
  21. }

1546C - AquaMoon and Strange Sort

对于每一个元素,肯定只能移动偶数距离

所以对于同一元素需要统计它们有多少个在奇数和偶数位置

原数组 Codeforces Round #732 (Div. 2) 思维场 - 图5 ,排序后数组 Codeforces Round #732 (Div. 2) 思维场 - 图6

对于每一个元素,如果它在 Codeforces Round #732 (Div. 2) 思维场 - 图7 中的奇数位置次数不同于在 Codeforces Round #732 (Div. 2) 思维场 - 图8 中奇数位置出现次数(偶数同理)则输出 NO,否则输出 YES

必须吐槽自己,大晚上写的代码不仔细,wa在 #38数据

  1. const int N = 1e6 + 10;
  2. int a[N], b[N], t[N][2];
  3. int main() {
  4. cin.tie(nullptr)->sync_with_stdio(false);
  5. int _; for (cin >> _; _--;) {
  6. int n; cin >> n;
  7. memset(t, 0, sizeof(t));
  8. for (int i = 1; i <= n; ++i)cin >> a[i], b[i] = a[i];
  9. sort(b + 1, b + 1 + n);
  10. for (int i = 1; i <= n; ++i) {
  11. t[a[i]][i & 1]++;
  12. t[b[i]][i & 1]--;
  13. }
  14. bool f = true;
  15. for (int i = 1; f and i <= 100000; ++i)
  16. if (t[i][0] || t[i][1]) f = false;
  17. cout << (f ? "YES\n" : "NO\n");
  18. }
  19. }

1546D - AquaMoon and Chess

看完题感觉是像某种组合数学题,但没思路

先贴一下dalao代码

  1. #define ll long long
  2. #define int int64_t
  3. constexpr int N = 1e5 + 5;
  4. constexpr int INF = 1e9 + 5;
  5. constexpr int mod = 998244353;
  6. int n, fac[N], invfac[N];
  7. string s;
  8. int carp(int x, int y) { return x * y % mod;}
  9. int binpow(int x, int y) {
  10. int res = 1;
  11. for (; y; y >>= 1, x = carp(x, x))
  12. if (y & 1) res = carp(res, x);
  13. return res;
  14. }
  15. int inv(int x) { return binpow(x, mod - 2);}
  16. void factorial() {
  17. fac[0] = 1;
  18. for (int i = 1; i < N; i++) fac[i] = carp(fac[i - 1], i);
  19. invfac[N - 1] = inv(fac[N - 1]);
  20. for (int i = N - 2; i >= 0; i--)
  21. invfac[i] = carp(invfac[i + 1], i + 1);
  22. }
  23. int nCr(int m, int r) { return carp(fac[m], carp(invfac[r], invfac[m - r]));}
  24. void solve() {
  25. cin >> n >> s;
  26. int z = 0, o = 0;
  27. for (int i = 0; i < n; i++) {
  28. int j = i;
  29. if (s[j] == '1') {
  30. while (j < n && s[j] == '1')
  31. j++;
  32. o += (j - i) / 2;
  33. i = j - 1;
  34. } else z++;
  35. }
  36. cout << nCr(z + o, o) << nl;
  37. }