AtCoder Beginner Contest 195 Editorial

Problem A - Health M Death(opens new window)

只要检查 \(H\equiv 0\) 即可.

  • Time complexity is \(\mathcal{O}(1)\).
  • Space complexity is \(\mathcal{O}(1)\).
Code(C++)
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int M, H;
cin >> M >> H;
cout << (H % M == 0 ? "Yes\n" : "No\n");
return 0;
}

Problem B - Many Oranges(opens new window)

注意 \(W\) 是以千克为单位,所以需要以 \(1000W\) 代替 \(W\)

首先先来分析上限:

尽可能使用 A 来达到上限,但问题是可能会有剩余的克数,我们需要将其分配给 \(B\) 即可

  • Time complexity is \(\mathcal{O}(1)\)).
  • Space complexity is \(\mathcal{O}(1)\).
Code (C++)
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int A, B, W;
cin >> A >> B >> W;
W *= 1000;
int minn = W / B;
int maxn = W / A;
if (minn + (W % B != 0) <= maxn) {
cout << minn + (W % B != 0) << ' ' << maxn << "\n";
} else {
cout << "UNSATISFIABLE\n";
}
return 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.
  • \(\cdots\)

基于以上模式可以很简单从 \(1000\) 开始,然后每 \(10\) 倍的递增直到超过 \(N\).

  • Time complexity is \(\mathcal{O}(\log_{10}N)\).
  • Space complexity is \(\mathcal{O}(1)\).
Code (Rust)
use proconio::input;
fn main() {
input! {
n: usize,
}
let mut base: usize = 1_000;
let mut ans: usize = 0;
let mut cnt = 3;
while base <= n {
let num = (n - base + 1).min(base * 9);
ans += num * (cnt / 3);
cnt += 1;
base *= 10;
}
println!("{}", ans);
}
Code (C++)
using ll = long long;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
ll n, ans = 0;
cin >> n;
if (n > 999) ans += n - 999;
if (n > 999999) ans += n - 999999;
if (n > 999999999) ans += n - 999999999;
if (n > 999999999999) ans += n - 999999999999;
if (n > 999999999999999) ans += n - 999999999999999;
cout << ans << "\n";
return 0;
}

Problem D - Shipping Center(opens new window)

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

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

  • Time complexity is \(\mathcal{O}(QM(N+\log M))\).
  • Space complexity is \(\mathcal{O}(1)\).
Code (C++)
using ll = long long;
typedef pair pii;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector wv(n);
vector x(m);
for (int i = 0; i < n; ++i) cin >> wv[i].second >> wv[i].first;
for (int i = 0; i < m; ++i) cin >> x[i];
sort(wv.begin(), wv.end(), greater());
while (q--) {
multiset s;
// 避免使用 Set 增加不必要的排序,因为上面已经排好序了
ll ans = 0;
int l, r;
cin >> l >> r;
for (int i = 0; i < l - 1; ++i) s.insert(x[i]);
for (int i = r; i < m; ++i) s.insert(x[i]);
multiset::iterator it;
for (int i = 0; i < n; ++i) {
if ((it = s.lower_bound(wv[i].second)) != s.end())
s.erase(it), ans += wv[i].first;
}
cout << ans << "\n";
// cout << "\n";
}
return 0;
}

Problem E - Lucky 7 Battle(opens new window)

不难发现,在这个游戏中,只有\(7\)的模数很重要。 因此,我们将精确地具有\(7\)个状态,表示当前的模数。

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

对于每一步,我们都会枚举所有 \(7\)个模,并计算其后继者:\(a =(last * 10)%7,b =(last * 10 + s [i])%7\)。

如果高桥移动,则他需要 \(a\)或\(b\)才能成为获胜状态(对于高桥来说),以便last将成为获胜状态。

如果Aoki移动,他需要 \(a\)和b\(b\)成为失败状态(对于Takahashi),以便last将成为失败状态,否则(a和b均为获胜状态),last将成为获胜状态。

并且我们只需要首先检查 \(0\) 是否为获胜状态。

  • Time complexity is \(\mathcal{O}(CN), where\ C=7\).
  • Space complexity is \(\mathcal{O}(C)\).
using ll = long long;
int p7[8] = {1, 3, 2, 6, 4, 5};
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int l;
cin >> l;
string s, t;
cin >> s >> t;
int mask = 1;
for (int i = l - 1; i >= 0; i--) {
int tg = (p7[(l - 1 - i) % 6] * (s[i] - '0')) % 7;
int nm = (mask << tg);
nm |= (nm >> 7);
nm &= (1 << 7) - 1;
if (t[i] == 'T') mask |= nm;
else
mask &= nm; // cout << mask << '\n';
}
cout << (mask & 1 ? "Takahashi\n" : "Aoki\n");
return 0;
}

AtCoder Beginner Contest 195 Editorial的更多相关文章

  1. AtCoder Beginner Contest 100 2018/06/16

    A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...

  2. AtCoder Beginner Contest 052

    没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...

  3. AtCoder Beginner Contest 053 ABCD题

    A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...

  4. AtCoder Beginner Contest 136

    AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...

  5. AtCoder Beginner Contest 137 F

    AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...

  6. AtCoder Beginner Contest 076

    A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...

  7. AtCoder Beginner Contest 079 D - Wall【Warshall Floyd algorithm】

    AtCoder Beginner Contest 079 D - Wall Warshall Floyd 最短路....先枚举 k #include<iostream> #include& ...

  8. AtCoder Beginner Contest 064 D - Insertion

    AtCoder Beginner Contest 064 D - Insertion Problem Statement You are given a string S of length N co ...

  9. AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle【暴力】

    AtCoder Beginner Contest 075 D - Axis-Parallel Rectangle 我要崩溃,当时还以为是需要什么离散化的,原来是暴力,特么五层循环....我自己写怎么都 ...

  10. AtCoder Beginner Contest 075 C bridge【图论求桥】

    AtCoder Beginner Contest 075 C bridge 桥就是指图中这样的边,删除它以后整个图不连通.本题就是求桥个数的裸题. dfn[u]指在dfs中搜索到u节点的次序值,low ...

随机推荐

  1. HTML中的常用的特殊字符以及所有特殊字符

    ## HTML常用特殊字符以下是HTML中常用的特殊符号及其编码: | 特殊符号 | 编码 | 描述 || --- | --- | --- || `<` | `&lt;` | 小于号 | ...

  2. LeetCode331:验证二叉树的前序序列化(递归)

    解题思路:把所有元素存成数组,设置一个全局下标next,表示当前节点如果要继续遍历应当从数组的哪个位置开始,然后从下标 0 开始DFS.如果DFS返回真并且next下标等于数组的长度,说明元素已经全部 ...

  3. Codeforces-470 div2 C题

    C. Producing Snow time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  4. HTB - CozyHosting - WriteUp

    CozyHosting 前言:抓紧赛季末上一波分,错过开vip才能练了 信息收集 扫描看看端口的开放情况,开了22,80,5555.这里fscan显示会跳转到cozyhosting.htb. 那就需要 ...

  5. 笔记本为什么不出可升级CPU的,用台式CPU不行吗?

    我十几年年前的thinkpad 通过更换cpu复活了:联想ThinkPad E430c i3变i7:笔记本电脑CPU升级思路-CPU参数 为什么现在的市面上可以更换cpu的笔记本非常稀少呢? inte ...

  6. 简单介绍JDK、JRE、JVM三者区别

    简单介绍JDK vs JRE vs JVM三者区别 文编|JavaBuild 哈喽,大家好呀!我是JavaBuild,以后可以喊我鸟哥,嘿嘿!俺滴座右铭是不在沉默中爆发,就在沉默中灭亡,一起加油学习, ...

  7. Spring Boot入坑-1-入坑准备&Spring简介

    [写在前面] 长期做基于Spring Boot的企业应用,计划将与应用相关的技术点,通过简介.步骤.示例的方式,记录并分享出来,用于作为Spring Boot入门的记录与教程 计划的内容有: Spri ...

  8. 2023-08-26:请用go语言编写。开心一下的智力题: 有一个村庄,一共250人, 每一个村民要么一定说谎,要么只说真话, 村里有A、B、C、D四个球队,且每个村民只会喜欢其中的一支球队, 但是说

    2023-08-26:请用go语言编写.开心一下的智力题: 有一个村庄,一共250人, 每一个村民要么一定说谎,要么只说真话, 村里有A.B.C.D四个球队,且每个村民只会喜欢其中的一支球队, 但是说 ...

  9. 文心一言 VS 讯飞星火 VS chatgpt (61)-- 算法导论6.4 5题

    文心一言 VS 讯飞星火 VS chatgpt (61)-- 算法导论6.4 5题 五.证明:在所有元素都不同的情况下,HEAPSORT 的时间复杂度是 Ω (nlgn). 文心一言: 要证明在所有元 ...

  10. Linux系统快速入门

    LINUX基础知识 I.Linux概述 linux是啥? 一套免费使用和自由传播的类Unix操作系统,是一个基于POSIX和Unix的多用户.多任务.支持多线程和多CPU的操作系统.它能运行主要的Un ...