AtCoder Beginner Contest 195 Editorial

Problem A - Health M Death(opens new window)

只要检查 AtCoder Beginner Contest 195 Editorial - 图1 即可.

  • Time complexity is AtCoder Beginner Contest 195 Editorial - 图2#card=math&code=%5Cmathcal%7BO%7D%281%29).
  • Space complexity is AtCoder Beginner Contest 195 Editorial - 图3#card=math&code=%5Cmathcal%7BO%7D%281%29).
  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int M, H;
  4. cin >> M >> H;
  5. cout << (H % M == 0 ? "Yes\n" : "No\n");
  6. return 0;
  7. }

Problem B - Many Oranges(opens new window)

注意 AtCoder Beginner Contest 195 Editorial - 图4 是以千克为单位,所以需要以 AtCoder Beginner Contest 195 Editorial - 图5 代替 AtCoder Beginner Contest 195 Editorial - 图6

首先先来分析上限:

尽可能使用 A 来达到上限,但问题是可能会有剩余的克数,我们需要将其分配给 AtCoder Beginner Contest 195 Editorial - 图7 即可

  • Time complexity is AtCoder Beginner Contest 195 Editorial - 图8#card=math&code=%5Cmathcal%7BO%7D%281%29)).
  • Space complexity is AtCoder Beginner Contest 195 Editorial - 图9#card=math&code=%5Cmathcal%7BO%7D%281%29).
  1. int main() {
  2. ios_base::sync_with_stdio(false), cin.tie(0);
  3. int A, B, W;
  4. cin >> A >> B >> W;
  5. W *= 1000;
  6. int minn = W / B;
  7. int maxn = W / A;
  8. if (minn + (W % B != 0)

Problem C - Comma(opens new window)

  • [1,9]: 9 numbers, each has 0 commas.
  • [10,99]: 90 numbers, each has 0 commas.
  • [100,999]: 900 numbers, each has 0 commas.
  • [1000,9999]: 9000 numbers, each has 1 comma.
  • AtCoder Beginner Contest 195 Editorial - 图10

基于以上模式可以很简单从 AtCoder Beginner Contest 195 Editorial - 图11 开始,然后每 AtCoder Beginner Contest 195 Editorial - 图12 倍的递增直到超过 AtCoder Beginner Contest 195 Editorial - 图13.

  • Time complexity is AtCoder Beginner Contest 195 Editorial - 图14#card=math&code=%5Cmathcal%7BO%7D%28%5Clog_%7B10%7DN%29).
  • Space complexity is AtCoder Beginner Contest 195 Editorial - 图15#card=math&code=%5Cmathcal%7BO%7D%281%29).
  1. use proconio::input;
  2. fn main() {
  3. input! {
  4. n: usize,
  5. }
  6. let mut base: usize = 1_000;
  7. let mut ans: usize = 0;
  8. let mut cnt = 3;
  9. while base
  1. using ll = long long;
  2. int main() {
  3. ios_base::sync_with_stdio(false), cin.tie(0);
  4. ll n, ans = 0;
  5. cin >> n;
  6. if (n > 999) ans += n - 999;
  7. if (n > 999999) ans += n - 999999;
  8. if (n > 999999999) ans += n - 999999999;
  9. if (n > 999999999999) ans += n - 999999999999;
  10. if (n > 999999999999999) ans += n - 999999999999999;
  11. cout << ans << "\n";
  12. return 0;
  13. }

Problem D - Shipping Center(opens new window)

第一眼看过去是线段树问题,但数据范围较小可以暴力找。

对于每个查询,我们收集所有可用的框,并根据其容量以升序对其进行排序。 对于每个盒子,我们从没有使用过的,盒子可以容纳的所有物品中,贪婪地选择最有价值的行李。

  • Time complexity is AtCoder Beginner Contest 195 Editorial - 图16)#card=math&code=%5Cmathcal%7BO%7D%28QM%28N%2B%5Clog%20M%29%29).
  • Space complexity is AtCoder Beginner Contest 195 Editorial - 图17#card=math&code=%5Cmathcal%7BO%7D%281%29).
  1. using ll = long long;
  2. typedef pair pii;
  3. int main() {
  4. ios_base::sync_with_stdio(false), cin.tie(0);
  5. int n, m, q;
  6. cin >> n >> m >> q;
  7. vector wv(n);
  8. vector x(m);
  9. for (int i = 0; i < n; ++i) cin >> wv[i].second >> wv[i].first;
  10. for (int i = 0; i < m; ++i) cin >> x[i];
  11. sort(wv.begin(), wv.end(), greater());
  12. while (q--) {
  13. multiset s;
  14. // 避免使用 Set 增加不必要的排序,因为上面已经排好序了
  15. ll ans = 0;
  16. int l, r;
  17. cin >> l >> r;
  18. for (int i = 0; i < l - 1; ++i) s.insert(x[i]);
  19. for (int i = r; i < m; ++i) s.insert(x[i]);
  20. multiset::iterator it;
  21. for (int i = 0; i < n; ++i) {
  22. if ((it = s.lower_bound(wv[i].second)) != s.end())
  23. s.erase(it), ans += wv[i].first;
  24. }
  25. cout << ans << "\n";
  26. // cout << "\n";
  27. }
  28. return 0;
  29. }

Problem E - Lucky 7 Battle(opens new window)

不难发现,在这个游戏中,只有AtCoder Beginner Contest 195 Editorial - 图18的模数很重要。 因此,我们将精确地具有AtCoder Beginner Contest 195 Editorial - 图19个状态,表示当前的模数。

从后开始,因为我们只知道游戏结束时的赢/输状态:$0 = \text{Takahashi获胜} ,\text {others} = \text{Aoki获胜} $

对于每一步,我们都会枚举所有 AtCoder Beginner Contest 195 Editorial - 图20个模,并计算其后继者:AtCoder Beginner Contest 195 Editorial - 图21

如果高桥移动,则他需要 AtCoder Beginner Contest 195 Editorial - 图22AtCoder Beginner Contest 195 Editorial - 图23才能成为获胜状态(对于高桥来说),以便last将成为获胜状态。

如果Aoki移动,他需要 AtCoder Beginner Contest 195 Editorial - 图24和bAtCoder Beginner Contest 195 Editorial - 图25成为失败状态(对于Takahashi),以便last将成为失败状态,否则(a和b均为获胜状态),last将成为获胜状态。

并且我们只需要首先检查 AtCoder Beginner Contest 195 Editorial - 图26 是否为获胜状态。

  • Time complexity is AtCoder Beginner Contest 195 Editorial - 图27%2C%20where%5C%20C%3D7#card=math&code=%5Cmathcal%7BO%7D%28CN%29%2C%20where%5C%20C%3D7).
  • Space complexity is AtCoder Beginner Contest 195 Editorial - 图28#card=math&code=%5Cmathcal%7BO%7D%28C%29).
  1. using ll = long long;
  2. int p7[8] = {1, 3, 2, 6, 4, 5};
  3. int main() {
  4. ios_base::sync_with_stdio(false), cin.tie(0);
  5. int l;
  6. cin >> l;
  7. string s, t;
  8. cin >> s >> t;
  9. int mask = 1;
  10. for (int i = l - 1; i >= 0; i--) {
  11. int tg = (p7[(l - 1 - i) % 6] * (s[i] - '0')) % 7;
  12. int nm = (mask << tg);
  13. nm |= (nm >> 7);
  14. nm &= (1 << 7) - 1;
  15. if (t[i] == 'T') mask |= nm;
  16. else
  17. mask &= nm;
  18. // cout << mask << '\n';
  19. }
  20. cout << (mask & 1 ? "Takahashi\n" : "Aoki\n");
  21. return 0;
  22. }