07 2025 档案

摘要:给定一个长度为 n 的整数数组 nums,要求统计所有满足以下条件的子序列‌的个数 子序列‌:定义为从原数组中按顺序选取的元素组成的序列(不要求连续)。 子序列中任意两个相邻元素的差值不超过 k(即 |nums[i] - nums[j]| ≤ k)。 结果取模‌:由于答案可能很大,输出结果对 10^ 阅读全文
posted @ 2025-07-27 22:30 最近饭吃的很多 阅读(17) 评论(0) 推荐(0)
摘要:比如数组 1 2 3 4 第一次将后三个减掉2 得到1 0 1 2 然后第二次 将1 0 1 2减掉1得到 0 0 0 1 再将1减掉1得到 0 0 0 0,操作3次使所有元素变为0 https://labuladong.online/algo/frequency-interview/bitwise 阅读全文
posted @ 2025-07-20 23:13 最近饭吃的很多 阅读(57) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/count-primes/description/ class Solution { public: bool isPrime(int x) { for (int i = 2; i * i <= x; ++i) { if (x % i == 阅读全文
posted @ 2025-07-20 18:07 最近饭吃的很多 阅读(5) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/largest-multiple-of-three/description/ 统计数字信息: 统计每个数字(0-9)出现的次数 统计数字对3取余的结果(0、1、2)的次数 计算所有数字的总和 处理总和余数: 如果总和能被3整除,直接使用所有数 阅读全文
posted @ 2025-07-20 18:01 最近饭吃的很多 阅读(8) 评论(0) 推荐(0)
摘要:https://www.nowcoder.com/discuss/774332771186565120?sourceSSR=search 重点: 求网格顶点,也就是又和竖线有交点又和横线有焦点 所以最重要的就是要确认x和y必须是整数,所以要求a和b的最大公约数 #include <iostream> 阅读全文
posted @ 2025-07-20 17:20 最近饭吃的很多 阅读(6) 评论(0) 推荐(0)
摘要:1.浮点数除法+四舍五入 #include <iostream> #include <iomanip> // 控制输出格式 #include <cmath> // 用于 round 函数 using namespace std; int main() { double a = 5; double b 阅读全文
posted @ 2025-07-12 15:57 最近饭吃的很多 阅读(37) 评论(0) 推荐(0)
摘要:每个数可以:+1,-1,不变,操作只能选一种,不能多次操作;最终的目标是统计某个数通过这些变换后出现的总次数。 知识点: map 容器中存储的数据是有序的,而 unordered_map 容器中是无序的。 unordered_map 1、优点:因为内部实现了哈希表,因此其查找速度非常的快。 2、缺点 阅读全文
posted @ 2025-07-12 15:04 最近饭吃的很多 阅读(148) 评论(0) 推荐(0)
摘要:1.求一个数组的最大公约数 输入: nums = {12, 24, 36, 48} 输出: 12 知识点: std::gcd(),求两个数的最大公约数 #include <iostream> #include <vector> #include <numeric> // 包含 gcd using n 阅读全文
posted @ 2025-07-12 14:01 最近饭吃的很多 阅读(10) 评论(0) 推荐(0)
摘要:给定一个整数数组 nums,你可以任意重排数组元素,将它排列成一个新的高度分布(每列的高度);然后在这个新的二维结构中找出一个最大的正方形;返回这个正方形的边长。 将数组从大到小排序; 遍历每个位置 i,查看前 i + 1 个元素是否能组成一个边长为 i + 1 的正方形; 即判断 heights[ 阅读全文
posted @ 2025-07-12 11:16 最近饭吃的很多 阅读(8) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problems/largest-perimeter-triangle/description/三角形两边之和大于第三边 将数组从大到小排序 只要能看到当前数大于两个数加起来,说明可以形成三角形 知识点: vector从大到小排序 sort(nums.begi 阅读全文
posted @ 2025-07-12 11:13 最近饭吃的很多 阅读(17) 评论(0) 推荐(0)
摘要:https://kamacoder.com/problempage.php?pid=1028 1.先统计字符串中每个字母出现的次数 2.计算每种字母能贡献的非空子序列数量 3.有dp[j]个子序列恰好包括j种字母, 4.动态规划初始化dp[0] = 1,空子序列只有一种 5.从 0 到 25 遍历所 阅读全文
posted @ 2025-07-10 11:38 最近饭吃的很多 阅读(13) 评论(0) 推荐(0)
摘要:相遇 排序后,遍历字典,碰到朝右走的记录个数,碰到朝左走的把朝右走的人个数全加起来。 #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<int, int> myMap; while(n--) 阅读全文
posted @ 2025-07-10 10:12 最近饭吃的很多 阅读(6) 评论(0) 推荐(0)
摘要:判断是否是素数 // 判断是否为质数: //小于2的数不是质数。 //遍历 2 到 √n,若存在因子则非质数。 bool isPrime(int n) { if (n < 2) return false; for (int i = 2; i <= sqrt(n); ++i) if (n % i == 阅读全文
posted @ 2025-07-09 16:07 最近饭吃的很多 阅读(26) 评论(0) 推荐(0)
摘要:链接:https://ac.nowcoder.com/acm/contest/11217/A 来源:牛客网dd在玩数字游戏,首先他拿到一个xxx 当xxx不为零时进行如下操作 如果二进制xxx中有奇数个111,则xxx二进制形式下最低位取反(即000变成111,111变成000) 如果二进制xxx中 阅读全文
posted @ 2025-07-06 21:14 最近饭吃的很多 阅读(26) 评论(0) 推荐(0)
摘要:https://www.luogu.com.cn/problem/P3368#ide 需要构造出原数组的差分数组d,然后用树状数组维护c数组 对于区间修改的话,我们只需要对差分数组进行操作即可,例如对区间[L,R]+k,那么我们只需要更新差分数组add(L,k),add(R+1,-k) #inclu 阅读全文
posted @ 2025-07-06 20:30 最近饭吃的很多 阅读(3) 评论(0) 推荐(0)
摘要:https://ac.nowcoder.com/acm/problem/15164 https://blog.csdn.net/TheWayForDream/article/details/118436732 求区间1-7的和=t[7]+t[6]+t[4] 求【x,y】的区间和 【x,y】=【1,y 阅读全文
posted @ 2025-07-06 18:13 最近饭吃的很多 阅读(5) 评论(0) 推荐(0)
摘要:https://www.nowcoder.com/practice/189a109747604763932024984f856d99?tpId=376&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fques 阅读全文
posted @ 2025-07-06 16:44 最近饭吃的很多 阅读(82) 评论(0) 推荐(0)