Contestant. Rank 3058. Rating -35. 坐大牢局 A. Showstopper 题意 给定两个序列 \(a, b\),规定一次操作为任取 \(i\),交换 \(a_i, b_i\)。输出任意次操作后,是否可以让 \(a_n = \max(a_i), b_n = \max(b_i)\)。 思路 首先,既然最后方案我们无需考虑,那么我们不妨定义 \(a\) 为最小值的序列,\(b\) 为最大值的序列,那么只要满足上面的条件,就是有解,否则无解。 时间复杂度:\(O(n)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define fs first #define sc second const int N = 2e5 + 10, inf = 0x3f3f3f3f3f3f3f3f; void init(){} void sol ...
Contestant. Rank 2267. Rating +74. A. Probably English 题意 给定一个字符串序列,输出序列中是否包含下面的 \(5\) 个单词: \(and, not, that, the, you\)。 思路 如题,别打错即可。 时间复杂度:\(O(n)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define fs first #define sc second const int N = 2e5 + 10, inf = 0x3f3f3f3f3f3f3f3f; void init(){} void solve() { vector<string> mp = {"and", "not", "that", "the", "you"}; int n; cin ...
Contestant. Rank 2183. Rating -13. A. Garland 题意 给定 \(4\) 盏灯的颜色,颜色为 \([0, 9]\) 内的任意数字。初始状态所有灯均关闭,打开一盏灯的条件是之前打开的灯的颜色与其不一致,第一次可以打开任意一盏灯。输出将所有灯打开所需最小次数。 思路 首先,这题只有 \(4\) 盏灯。 所以,我们直接分类讨论即可。 我们先将灯按照颜色代码升序排序,那么如果第一个数和最后一个数相等,输出 \(-1\); 否则,前三个数相等或者后三个数相等时,需要 \(6\) 次; 否则,\(4\) 次足矣。 时间复杂度:\(O(4 \log 4)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define fs first #define sc second const int N = 2e5 + 10, inf = 0x3f3f3f ...
Contestant(alt). Rank 5166. Rating -27(+123 -150). A. Plus or Minus 题意 给定三个数 \(a, b, c\),判断 \(a+b = c\) 还是 \(a - b = c\),前者输出 \(+\),后者输出 \(-\),保证有解。 思路 如题。 时间复杂度:\(O(1)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> const int N = 1.5e6 + 10, inf = 0x3f3f3f3f3f3f3f3f; void solve(){ int a, b, c; cin >> a >> b >> c; if(a + b == c) cout << '+' << '\n'; else cout << '-' << '\n' ...
Contestant. Rank 2. Solved 4/8. A. ACM? 你也想打ACM? 题意 对于 \(n\) 道题,给定 \(k\) 个提交记录,规定罚时为 \(20\) 分钟,按照 \(ACM/ICPC\) 赛制计算通过题数和总用时。 思路 首先,没过的题不算罚时,过了的题重复提交无效。 因为题给数据是按照时间排序的,那么,我们不妨从前往后遍历,用数组记录当前的状态。 对于下面的 \(AC\) 代码,其中 \(ok_i\) 表示当前是否过了 \(i\) 题;\(a_i\) 表示第 \(i\) 道题最早是在 \(a_i\) 时刻通过的;\(p_i\) 表示第 \(i\) 道题在通过前 \(WA\) 了几次。 最后,我们遍历所有题,如果过题了,记录过题数,并将总用时加上 \(a_i + 20p_i\)。 时间复杂度:\(O(nk)\) 本题测试点数据量过大,java需要使用快读,cpp若使用cin需要关闭输入输出流同步 对应AC代码 (cpp) #include <bits/stdc++.h> using namespace ...
Contestant. Rank 1245. Rating +30. A. Walking Master 题意 给定两个点 \((a, b), (c, d)\),定义对于点 \((x, y)\) 的操作为下面任选一: \(x + 1, y + 1\); \(x - 1\) 输出从 \((a, b)\) 走到 \((c, d)\) 需要的最小操作数,无解输出 \(-1\)。 思路 画个图即可。 首先,我们需要向上移动 \(d - b\),如果 \(d - b < 0\) 就是无解。 此时,横坐标变为 \(a + d - b\),还需要向左移动 \(a + d - b - c\),如果 \(a + d - b - c < 0\) 也是无解。 若有解,输出 \(d - b + a + d - b - c\)。 时间复杂度:\(O(1)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long #define pii ...
Contestant. Rank 1755. Rating +54. A. Lame King 题意 给定一个坐标系,其中 \(x \in [-100, 100], y \in [-100, 100]\)。给定一个坐标 \([s, t]\),输出按规定从 \([0, 0]\) 走到 \([s, t]\) 需要的最短时间。 规定若需要连续从相同方向移动,需要间隔一秒。 思路 首先,若我们需要一直向右,那么停留一秒绝对比向垂直方向绕路快,所以,我们不妨以折线的方式移动,直到横坐标或纵坐标等于终点时,向同一方向间隔移动。 时间复杂度:\(O(1)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> const int N = 2e5 + 10, inf = 0x3f3f3f3f3f3f3f3f, mod = 998244353; void init(){} voi ...
Virtual Participant. Unofficial Rank 382. Solved 4/7. A. Likes 题意 定义 \(a_i\) 为一个人对 \(|a_i|\) 的"喜欢"状态,当 \(a_i > 0\) 时,该人对 \(|a_i|\) 点了"喜欢",否则将其撤回了"喜欢"。规定未点喜欢就不能撤回"喜欢"。 给定打乱顺序后的若干人的"喜欢"操作,定义 \(b_i\) 为进行第 \(i\) 次操作后得到的"喜欢"数量。将操作按一定方案排序,输出让每次操作得到的数量最大和最小的序列 \(b\)。 思路 首先,若要让数量最少,我们直接在点了"喜欢"后立刻取消即可,那么最后得到的答案会有 \(x\) 个 \(0\ 1\),\(x\) 即为负数的个数。剩余的数只能让 \(b\) 严格递增 \(1\)。 若要让数量最多,那么我们只需在全部点完后再取消。这时得到一个先递增后递减的序列。 时间复杂度:\(O(n)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; ...
Practice. A. Sum 题意 给定三个数,输出是否可以找出一个数,满足其为另外两个数的和。 思路 如题。 时间复杂度:\(O(1)\) 对应AC代码 #include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> void solve(){ int a, b, c; cin >> a >> b >> c; cout << (a + b == c || a + c == b || b + c == a ? "YES\n" : "NO\n"); } signed main(){ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int t; cin >> t; while(t --) solve(); } 如题 B. Increasin ...