复习dddddddd
1.

思路:用队列先进先出的特性
#include <iostream>
#include <vector>
#include <stack>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <list>
#include <map>
#include <set>using namespace std;int main() {int n; cin >> n;queue<pair<int, int>>arr; // 下标,值n = pow(2, n);for (int i = 1; i <= n; i++) {int temp;cin >> temp;arr.push({ i,temp });}while (arr.size() > 2) {auto l = arr.front();arr.pop();auto r = arr.front();arr.pop();if (l.second > r.second)arr.push({ l.first,l.second });else arr.push({ r.first,r.second });}auto l = arr.front();arr.pop();auto r = arr.front();if (l.second > r.second)cout << r.first;else cout << l.first;return 0;
}
2.

思路:二叉树的数组定义来写
#include <iostream>
#include <vector>
#include <stack>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <list>
#include <map>
#include <set>using namespace std;struct Node {int l, r;
}s[1000001];
int tt = -1;void dfs(int n,int coun) {if (n==0)return;tt = max(tt, coun);dfs(s[n].l, coun + 1);dfs(s[n].r, coun + 1);
}int main() {int n; cin >> n;for (int i = 1; i <= n; i++)cin >> s[i].l >> s[i].r;dfs(1,1);cout << tt << endl;return 0;
}
3.

思路: 用递归的方法来分出左右子树,以及以其为子节点为节点的左右子树,直到叶子节点
#include <iostream>
#include <vector>
#include <stack>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <list>
#include <map>
#include <set>using namespace std;void func(string& s1, string& s2) {char root = s1[0];int l = s2.find(root), r = s1.size() - l - 1;if (l) {string str1 = s1.substr(1, l), str2 = s2.substr(0, l);func(str1, str2);}if (r) {string str1 = s1.substr(l + 1), str2 = s2.substr(l + 1);func(str1, str2);}cout << root;}int main() {string s1, s2;cin >> s2 >> s1;func(s1, s2);return 0;
}
4.

思路:广搜探索所有的组成方式
#include <iostream>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <vector>
using namespace std;typedef pair<string, string> Rule;int bfs(const string& A, const string& B, const vector<Rule>& rules) {if (A == B) return 0; queue<pair<string, int>> q; q.push({A, 0});unordered_set<string> visited; visited.insert(A);while (!q.empty()) {auto current = q.front();q.pop();string currentStr = current.first;int steps = current.second;if (currentStr == B) {return steps;}if (steps >= 10) {continue;}for (const auto& rule : rules) {const string& from = rule.first;const string& to = rule.second;size_t pos = currentStr.find(from);while (pos != string::npos) {string newStr = currentStr;newStr.replace(pos, from.length(), to);if (visited.find(newStr) == visited.end()) {visited.insert(newStr);q.push({newStr, steps + 1});}pos = currentStr.find(from, pos + 1);}}}return -1;
}int main() {string A, B;cin >> A >> B;vector<Rule> rules;string a, b;while (cin >> a >> b) {rules.push_back({a, b});}int result = bfs(A, B, rules);if (result != -1) {cout << result << endl;} else {cout << "NO ANSWER!" << endl;}return 0;
}
5.算阶

思路:二进制枚举每个位置上能否放1,经过整个流程后还是1,则则这个位置是1,同时整个的值也要小于m才是ans
#include <iostream>
#include <vector>
#include <stack>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <list>
#include <map>
#include <set>using namespace std;pair<string, int> operations[100005];
int n, m;int calc(int bit, int now) {for (int i = 1; i <= n; i++) {int x = operations[i].second >> bit & 1;if (operations[i].first == "AND") now &= x;else if (operations[i].first == "OR") now |= x;else now ^= x;}return now;
}int main() {cin >> n >> m;for (int i = 1; i <= n; i++) {char str[5]; int num;scanf("%s%d", str, &num);operations[i] = make_pair(str, num);}int val = 0, ans = 0;for (int bit = 29; bit >= 0; bit--) {int res0 = calc(bit, 0);int res1 = calc(bit, 1);if ((val + (1 << bit)) <= m && res0 < res1) {val += 1 << bit; ans += res1 << bit;}else {ans += res0 << bit;}}cout << ans << endl;return 0;
}
6.

思路:
解题思路
-
唯一分解定理:
a=p1k1⋅p2k2⋅⋯⋅pnkn
将 a 分解为素数的乘积:则 ab 的因子和为:
σ(ab)=(1+p1+p12+⋯+p1k1⋅b)⋅(1+p2+p22+⋯+p2k2⋅b)⋅⋯⋅(1+pn+pn2+⋯+pnkn⋅b) -
等比数列求和:
Si=1+pi+pi2+⋯+piki⋅b=pi−1piki⋅b+1−1
对于每个素数 pi,其对应的等比数列和为: -
模运算性质:
由于结果需要对 9901 取模,我们需要在计算过程中对每一步结果取模,避免溢出。 -
快速幂算法:
计算 piki⋅b+1 时,使用快速幂算法提高效率。 -
逆元计算:
在计算等比数列和时,分母 pi−1 可能不为 1,因此需要计算 pi−1 在模 9901 下的逆元。
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;const int MOD = 9901;// 快速幂算法
long long fastPow(long long base, long long exp, long long mod) {long long result = 1;while (exp > 0) {if (exp & 1) {result = (result * base) % mod;}base = (base * base) % mod;exp >>= 1;}return result;
}// 扩展欧几里得算法求逆元
int extendedEuclidean(int a, int m, int& x, int& y) {if (m == 0) {x = 1;y = 0;return a;}int x1, y1;int gcd = extendedEuclidean(m, a % m, x1, y1);x = y1;y = x1 - (a / m) * y1;return gcd;
}// 计算 a 在模 m 下的逆元
int modularInverse(int a, int m) {int x, y;int gcd = extendedEuclidean(a, m, x, y);if (gcd != 1) {return -1; // 逆元不存在} else {return (x % m + m) % m; // 确保结果为正}
}// 分解质因数
vector<pair<int, int>> primeFactorization(int n) {vector<pair<int, int>> factors;for (int i = 2; i * i <= n; i++) {if (n % i == 0) {int count = 0;while (n % i == 0) {n /= i;count++;}factors.push_back({i, count});}}if (n > 1) {factors.push_back({n, 1});}return factors;
}// 计算 a^b 的因子和对 MOD 取模
int sumOfDivisors(int a, int b) {if (a == 0) return 0; // 0^b 的因子和为 0if (b == 0) return 1; // a^0 的因子和为 1// 分解质因数vector<pair<int, int>> factors = primeFactorization(a);long long result = 1;for (const auto& factor : factors) {int p = factor.first;int k = factor.second;// 计算等比数列和 S = (p^(k*b + 1) - 1) / (p - 1)long long numerator = (fastPow(p, k * b + 1, MOD) - 1 + MOD) % MOD;long long denominator = (p - 1) % MOD;// 如果 p == 1,等比数列和为 k * b + 1if (p == 1) {result = (result * (k * b + 1)) % MOD;continue;}// 计算分母的逆元int inv = modularInverse(denominator, MOD);if (inv == -1) {// 如果分母为 0,等比数列和为 k * b + 1result = (result * (k * b + 1)) % MOD;} else {// 计算 S 并对 MOD 取模long long S = (numerator * inv) % MOD;result = (result * S) % MOD;}}return result;
}int main() {int a, b;cin >> a >> b;cout << sumOfDivisors(a, b) << endl;return 0;
}
7.逆元
逆元是数论中的一个重要概念,尤其在模运算中广泛应用。它的核心思想是解决模意义下的“除法”问题。因为模运算中除法并不直接定义,而是通过乘法逆元来实现。
1. 逆元的定义
给定一个整数 a 和一个模数 m,如果存在一个整数 x,使得:
a⋅x≡1(modm)
则称 x 是 a 在模 m 下的乘法逆元,记作 a−1。
2. 将模等式转化为常规等式
模等式 a⋅x≡1(modm) 可以转化为常规等式:
a⋅x+m⋅k=1
其中 k 是某个整数。这个等式表明,a⋅x 与 1 的差是 m 的倍数。
3. 逆元的存在条件
a 在模 m 下的逆元存在的充要条件是 a 和 m 互质,即:
gcd(a,m)=1
如果 a 和 m 不互质,则 a 在模 m 下没有逆元。
4. 逆元的计算方法
(1) 扩展欧几里得算法
扩展欧几里得算法可以求解方程 a⋅x+m⋅k=1。如果 gcd(a,m)=1,则 x 就是 a 在模 m 下的逆元。
步骤:
- 使用扩展欧几里得算法求解 gcd(a,m) 以及 x 和 k。
- 如果 gcd(a,m)=1,则 x 是 a 的逆元。
- 将 x 调整为正数(通过取模)。
#include <iostream>
using namespace std;// 扩展欧几里得算法
int extendedEuclidean(int a, int m, int& x, int& y) {if (m == 0) {x = 1;y = 0;return a;}int x1, y1;int gcd = extendedEuclidean(m, a % m, x1, y1);x = y1;y = x1 - (a / m) * y1;return gcd;
}// 计算 a 在模 m 下的逆元
int modularInverse(int a, int m) {int x, y;int gcd = extendedEuclidean(a, m, x, y);if (gcd != 1) {return -1; // 逆元不存在} else {return (x % m + m) % m; // 确保结果为正}
}int main() {int a, m;cout << "请输入 a 和 m: ";cin >> a >> m;int inv = modularInverse(a, m);if (inv == -1) {cout << a << " 在模 " << m << " 下没有逆元。" << endl;} else {cout << a << " 在模 " << m << " 下的逆元是: " << inv << endl;}return 0;
}
(2) 费马小定理
如果模数 m 是素数,且 a 不是 m 的倍数,则根据费马小定理:
a^m−1≡1(modm)
因此,a 的逆元为:
a−1≡a^m−2(modm)
#include <iostream>
using namespace std;// 快速幂算法
long long fastPow(long long a, long long b, long long mod) {long long result = 1;while (b > 0) {if (b & 1) {result = (result * a) % mod;}a = (a * a) % mod;b >>= 1;}return result;
}// 计算 a 在模 m 下的逆元(费马小定理)
int modularInverse(int a, int m) {return fastPow(a, m - 2, m);
}int main() {int a, m;cout << "请输入 a 和 m: ";cin >> a >> m;if (m <= 1 || a % m == 0) {cout << a << " 在模 " << m << " 下没有逆元。" << endl;} else {int inv = modularInverse(a, m);cout << a << " 在模 " << m << " 下的逆元是: " << inv << endl;}return 0;
}
逆元运用
5. 逆元的应用
- 模意义下的除法:
- 在模运算中,a/b 等价于 a⋅b−1(modm)。
- 线性同余方程:
- 解方程 a⋅x≡b(modm) 时,需要用到 a 的逆元。
- 组合数学:
- 计算组合数 C(n,k) 时,通常需要用到模意义下的除法。
- 密码学:
- RSA 加密算法中,逆元用于计算私钥。
相关文章:
复习dddddddd
1. 思路:用队列先进先出的特性 #include <iostream> #include <vector> #include <stack> #include <cstdio> #include <algorithm> #include <cstring> #include <climits> #include <cstdlib> #include <cma…...
大数据技术Kafka详解 ⑥ | Kafka大厂面试题
目录 1、为什么要使用kafka? 2、kafka消费过的消息如何再消费? 3、kafka的数据是放在磁盘上还是内存上,为什么速度会快? 4、kafka数据怎么保障不丢失? 4.1、生产者数据的不丢失 4.2、消费者数据的不丢失 4.3、kafka集群中的broker的数据不丢失 5、采集数…...
Jupyter里面的manim编程学习
1.Jupyterlab的使用 因为我之前一直都是使用的vscode进行manim编程的,但是今天看的这个教程使用的是Jupyter,我也很是好奇这个manim在Jupyter这样的交互式下面会生成怎么样的效果,所以今天尝试了jupyter,并且对于两个进行比较和说…...
hot100_19. 删除链表的倒数第 N 个结点
hot100_19. 删除链表的倒数第 N 个结点 思路 给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。 示例 1: 输入:head [1,2,3,4,5], n 2 输出:[1,2,3,5] 示例 2: 输入:head […...
✨1.HTML、CSS 和 JavaScript 是什么?
✨✨ HTML、CSS 和 JavaScript 是构建网页的三大核心技术,它们相互协作,让网页呈现出丰富的内容、精美的样式和交互功能。以下为你详细介绍: 🦋1. HTML(超文本标记语言) 定义:HTML 是一种用于描…...
机器学习的数学基础(三)——概率与信息论
目录 1. 随机变量2. 概率分布2.1 离散型变量和概率质量函数2.2 连续型变量和概率密度函数 3. 边缘概率4. 条件概率5. 条件概率的链式法则6. 独立性和条件独立性7. 期望、方差和协方差7.1 期望7.2 方差7.3 协方差 8. 常用概率分布8.1 均匀分布 U ( a , b ) U(a, b) U(a,b)8.2 Be…...
flutter将utf-8编码的字节序列转换为中英文字符串
这里遇到的问题是,我通过某种方式拿到了utf-8编码的字节序列,我只知道他们对应的是中英文字符。怎么将其转成中英文,并打印,让我对utf-8编码有了些许许的了解。 这里记录一下转换代码: String wifiName \xE9\xA1\xB…...
IM聊天系统架构实现
一、IM系统整体架构 二、企业级IM系统如何实现心跳与断线重连机制; 1、重连机制(服务端下线) 服务端下线,客户端netty可以感知到,在感知的方法中进行重连的操作,注意重连可能连接到旧的服务器继续报错&…...
基于腾讯云大模型知识引擎×DeepSeek构建八字、六爻赛博算卦娱乐应用
引言 随着DeepSeek的火爆,其强大的思维链让不少人越用越香,由于其缜密的思维和推理能力,不少人开发出了不少花里胡哨的玩法,其中一种就是以八字、六爻为代表的玄学文化正以“赛博玄学”的新形态席卷年轻群体。 针对于八字、六爻…...
k8s ssl 漏洞修复
针对Kubernetes集群中SSL/TLS协议信息泄露漏洞(CVE-2016-2183)的修复,需重点修改涉及弱加密算法的组件配置。以下是具体修复步骤及验证方法: 一、漏洞修复步骤 1. 修复etcd服务 修改配置文件 : 编辑 /etc/kubernetes/…...
linux文件管理命令ln
linux文件管理命令ln 1、软链接2、硬链接3、命令参数3.1、必要参数3.2、选择参数 4、应用示例4.1、创建硬链接4.2、创建软链接(符号链接)4.3、 对目录创建软链接4.4、强制覆盖目标文件 5、应用场景 它的功能是为某一个文件在另外一个位置建立一个同步的链…...
CT dicom 去除床板 去除床位,检查床去除
1. 前言 医院拍摄患者CT与MRI 图像, 但是CT图像中就会出现检查床的区域,来看CT扫描设备是什么样子的,红色标出区域 可以在图中看到,在头部位置安装有固定头部的类似支架的东西,这个东西拍摄出来时什么样子呢ÿ…...
扩散模型中,Flow Matching的训练方式相比于 DDPM 训练方法有何优势?
在扩散模型中,Flow Matching(FM)相比DDPM(Denoising Diffusion Probabilistic Models)的训练方法具有以下核心优势: 1. 更简单的训练目标 DDPM:通过逐步预测噪声来间接优化数据分布的变分下界(ELBO),需要设计多步的噪声调度策略,训练目标依赖马尔可夫链的分解。Flow…...
【用deepseek和chatgpt做算法竞赛】——还得DeepSeek来 -Minimum Cost Trees_5
往期 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_0:介绍了题目和背景【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_1:题目输入的格式说明,选择了邻接表…...
Python实现GO鹅优化算法优化随机森林分类模型项目实战
说明:这是一个机器学习实战项目(附带数据代码文档视频讲解),如需数据代码文档视频讲解可以直接到文章最后关注获取。 1.项目背景 在当今数据驱动的世界中,机器学习技术被广泛应用于各种领域,如金融、医疗、…...
【目标检测】【YOLOv4】YOLOv4:目标检测的最佳速度与精度
YOLOv4:目标检测的最佳速度与精度 0.论文摘要 有许多特征被认为可以提高卷积神经网络(CNN)的准确性。需要在大规模数据集上对这些特征的组合进行实际测试,并对结果进行理论上的验证。某些特征仅适用于特定模型和特定问题&#…...
常用电脑,护眼软件推荐 f.lux 3400K | 撰写论文 paper
常用电脑?平均每天用 5 个小时?你就要考虑用一个护眼软件了,对皮肤也好。因为电脑屏幕有辐射,比如蓝光。 f.lux 作为一款专业护眼软件,值得使用。之前用了三年的 Iris Pro,现在 f.lux 做的更好了。 使用…...
算法模板(二分法开区间模板,二分法闭区间模板)
二分法闭区间模板: class Solution {// lower_bound 返回最小的满足 nums[i] > target 的 i// 如果数组为空,或者所有数都 < target,则返回 nums.size()// 要求 nums 是非递减的,即 nums[i] < nums[i 1]// 闭区间写法i…...
新手小白如何挖掘cnvd通用漏洞之存储xss漏洞(利用xss钓鱼)
视频教程和更多福利在我主页简介或专栏里 (不懂都可以来问我 专栏找我哦) 如果对你有帮助你可以来专栏找我,我可以无偿分享给你对你更有帮助的一些经验和资料哦 目录: 一、XSS的三种类型: 二、XSS攻击的危害&#x…...
ros通信与回调函数多线程应用
一、ros topic通信流程 参考资料: 一个ros节点至少有几个线程(1058): https://zhuanlan.zhihu.com/p/680188065 鱼香rostopic底层流程(1005~1008): https://zhuanlan.zhihu.com/p/656716718 王方浩-ROS发布订阅实现(二): https://zhuanlan.zhihu.com/p/439208597 基础的topic…...
【蓝桥杯集训·每日一题2025】 AcWing 6134. 哞叫时间II python
6134. 哞叫时间II Week 1 2月20日 农夫约翰正在试图向埃尔茜描述他最喜欢的 USACO 竞赛,但她很难理解为什么他这么喜欢它。 他说「竞赛中我最喜欢的部分是贝茜说『现在是哞哞时间』并在整个竞赛中一直哞哞叫」。 埃尔茜仍然不理解,所以农夫约翰将竞赛…...
【CXX】5 桥接模块参考
1 CXX主要概念概览已经涵盖了CXX用来表示语言边界的高级模型。本章在此基础上详细介绍#[cxx::bridge]的语法和功能。 extern “Rust” ——将不透明的Rust类型、Rust函数、Rust方法暴露给C;具有生命周期的函数。extern“C”——绑定不透明的C类型、C函数、C成员函数…...
open62541,有点问题
要运行 open62541 提供的示例服务端程序,您需要确保以下几点: 代码已正确编译。了解如何启动服务端示例。确认服务端是否正常运行。 以下是详细的步骤和说明: 1. 确保代码已正确编译 在运行任何示例之前,您需要先完成项目的构建…...
智能交通系统(Intelligent Transportation Systems):智慧城市中的交通革新
智能交通系统(Intelligent Transportation Systems, ITS)是利用先进的信息技术、通信技术、传感技术、计算机技术以及自动化技术等,来提升交通系统效率和安全性的一种交通管理方式。ITS通过收集和分析交通数据,智能化地调度、控制…...
【TOT】Tree-of-Thought Prompting
Tree-of-Thought Prompting Tree-of-Thought Prompting In one example, a ToT prompt improves ChatGPT 3.5’s reasoning ability to answer a question that could previously only be answered by ChatGPT 4. 赋予了gpt3 推理能力,这能力只有gpt4才有。 增强、反馈和贡献 …...
内置函数用法
目录 1. 概述 2. 数学运算 2.1 求绝对值函数 abs( ) 2.2 取近似值 round( ) 2.3 求次方 pow( ) 2.4 求商和余数 divmod( ) 2.5 求最大值 max( ) 2.6 求最小值 min( ) 2.7 求累加和 sum( ) 2.8 eval( ) 3. 类型转换 3.1 #ord( ):字…...
基于LM Arena 的 LLM 基准测试排行榜:DeepSeek-R1 排名第 5
打开 Arena 网站:https://lmarena.ai/,点开 Leaderboard 可以看到上图的排行榜,可以看到 DeepSeek-R1 排名第 5。...
图数据库Neo4j面试内容整理-建模实践
在 Neo4j 中进行图数据建模(Graph Modeling)是设计和构建高效图数据库系统的关键。图数据库与关系型数据库不同,图数据建模强调的是如何通过节点、关系、标签和属性来表示和组织数据之间的复杂联系。因此,图数据库的建模过程不仅需要理解数据本身,还需要考虑查询的效率和扩…...
晶闸管的串联使用
1、何时需要使用晶闸管串联 单个晶闸管的额定电压是有一定限度的,当实际电路要求晶闸管承受的电压值大于单个晶闸管的额定电压时,可以用两个或两个以上同型号的晶闸管串联起来使用。 多个晶闸管串联时,由于各晶闸管的特性不可能完全一致,这样将导致晶闸管在阻断状态、开通与…...
【QT】第一个 QT程序(对象树)
🌈 个人主页:Zfox_ 🔥 系列专栏:Qt 目录 一:🔥 QtHelloWorld程序 🦋 使⽤"标签"实现纯代码⽅式实现可视化操作实现 🦋 使⽤"按钮"实现可视化操作实现纯代码实现…...
