Introduction Recursion is a fascinating concept in computer science where a function calls itself to solve a problem. Think of it like a set of Russian nesting dolls, where each doll contains a smaller version of itself. In programming, a recursive f...
A. 评估 关键在于 \(|a_i| \le 1000\),所以可以开一个长度为 2000 的数组统计一下每个值的个数,然后 \(\Theta(n^2)\) 处理这个 2000 的数组。 #include <iostream> using namespace std; const int N = 2010; int a[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { ...
A. 序列 逻辑非常简单,先输出 k 个 0 之后 01 交替输出直到把 0 用完,最后输出剩下的 1. #include <iostream> using namespace std; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= k; ++i) { printf("0"); m--; } while (n || ...
题面可以看这里. A. 数列计数 最害怕的数学题。 \(\prod_{i=1}^{n}\binom{a_i}{b_i} \) 等价于对于每一个 i,都有 \(\binom{a_i}{b_i}\) 为奇数。 对于 \(\binom{n}{k}\),根据(ChatGPT指出的)卢卡斯定理,取 p = 2 有 \[\binom{n}{k} \equiv \binom{n\ \text{mod}\ 2}{k\ \text{mod}\ 2} \binom{\lfloor\frac{n}{2}\rfloor...
Problem Statement Given an integer array nums, return an array answer such that: answer[i] = product of all elements in nums except nums[i] 🔍 Intuition If we could use division, a simple approach would be: Calculate the product of all elements. D...
Why use a heavyweight IDE when JetBrains Fleet delivers everything—fast and clean? I've recently adopted JetBrains Fleet for C++ development on Arch Linux, and it's quickly become my preferred setup for both competitive programming and SDL2 graphics ...
Problem:Given an array of strings strs, group the anagrams together. You can return the answer in any order. 📌 Example: Input: strs = ["eat", "tea", "tan", "ate", "nat", "bat"] Output: [["bat"], ["nat","tan"], ["ate","eat","tea"]] 🧠 Intuition All...
Problem Summary You are given a tree with n nodes rooted at node 1, and each edge initially has a weight of 0. The task is to assign each edge a weight of either 1 or 2. The cost of a path is defined as the sum of edge weights along the path. Use the...
昨天栽在二分了,今天写了四个二分一个也没挂,爽😋 A. 互质划分 事实上,只需要 n / 2 即可,如果所有 2 的倍数都能分开了,那其他的更能分开。 #include <iostream> #include <cmath> using namespace std; int main() { long long n; cin >> n; cout << max(1LL, n >> 1) << endl; return 0; } B. 出租车 对于每一个居民...
A. 染色 数据非常小,直接暴力就可以,非常保险。 #include <iostream> using namespace std; int main() { int l1, r1, l2, r2; cin >> l1 >> r1 >> l2 >> r2; int res = 0; for (int i = 0; i <= 100; ++i) { if (l1 <= i && i < r2 && l2 <= i && i < r1) { ...