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) { ...
A. 傻鹿尖塔 每次临死前贪心选择前面能选的最大的即可,但是需要注意不要直接中途 break,会影响之后的读入 😭😭😭 #include <iostream> #include <queue> using namespace std; int n, m, k; int a[100010]; priority_queue<int> q; int main() { int T; scanf("%d", &T); while (T--) { whil...
第一场打完觉的非常水,于是第二场立刻就被真实了,已老实求放过😇😇😇。 A. 舞蹈机器人 熟悉的情况,熟悉的打表( 打表 #include <iostream> #include <set> using namespace std; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; set<pair<int, int>> s; void dfs(int x, int y, int dep, int lim, bool f) { ...
A. 熊孩子打卡 一道比较水的签到题,因为数据不算太大,直接开 map 统计就可以。 #include <cstdio> #include <map> using namespace std; map<int, int> mp; int main() { int n, res = 0, ls = __INT_MAX__; // 数据肯定到不了 __INT_MAX__ scanf("%d", &n); for (int i = 1; i <= n; ++i) { ...
Date: 2024-10-14 This article explains modular arithmetic operations in Java, crucial for handling large numbers in competitive programming. It covers modular addition, subtraction, multiplication, and exponentiation, emphasizing the use of the modu...