摘要: 堆排序C++代码模板 // 下沉调整函数 void sift_down(vector<int>& arr, int i, int n) { int largest = i; // 当前节点 int left = 2 * i + 1; // 左子节点 int right = 2 * i + 2;// 阅读全文
posted @ 2025-03-25 19:43 Tshaxz 阅读(45) 评论(0) 推荐(0)
摘要: 大根堆/最大堆 以下是 大根堆(Heap)的C++代码模板,包含最大堆的基本操作(插入、删除堆顶、堆化等),注释详细说明关键步骤: class MaxHeap { private: vector<int> heap; // 获取父节点索引 int parent(int i) { return (i 阅读全文
posted @ 2025-03-25 19:34 Tshaxz 阅读(470) 评论(0) 推荐(0)
摘要: ![image](https://img2024.cnblogs.com/blog/2498334/202503/2498334-20250324175942571-265324784.png) ![image](https://img2024.cnblogs.com/blog/2498334/202503/2498334-20250324175952608-1162837386.png) ![i 阅读全文
posted @ 2025-03-24 18:03 Tshaxz 阅读(28) 评论(0) 推荐(0)
摘要: Git 常用命令速查手册 1. 初始化与克隆 ​初始化仓库 git init ​克隆远程仓库 git clone <repository_url> 2. 配置信息 ​设置全局用户名 git config --global user.name "Your Name" ​设置全局邮箱 git confi 阅读全文
posted @ 2025-03-07 17:15 Tshaxz 阅读(29) 评论(0) 推荐(0)
摘要: 判断合法的ipv4或ipv6地址 468. 验证IP地址 - 力扣(LeetCode) 模拟题 93. 复原 IP 地址 - 力扣(LeetCode) 回溯算法 给出完整ipv6地址,输出压缩后的ipv6地址 P2815 IPv6地址压缩 模拟题 给出压缩后的ipv6地址,输出复原后的完整ipv6地 阅读全文
posted @ 2025-03-06 15:14 Tshaxz 阅读(40) 评论(0) 推荐(0)
摘要: 从标准输入读取示例: std::tm tm = {}; std::cout << "请输入日期时间 (YYYY-MM-DD HH:MM:SS): "; std::cin >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S"); if (std::cin.fail()) 阅读全文
posted @ 2025-03-06 14:23 Tshaxz 阅读(113) 评论(0) 推荐(0)
摘要: 做714. 买卖股票的最佳时机含手续费 - 力扣(LeetCode)时,写function形式的dfs结果超时了,换成C++23以上的auto写法就可以过。 这两种写法的区别如下: 省流版:显示递归auto写法比function快50~100倍 写法一,显示递归模版,C++23起支持 auto df 阅读全文
posted @ 2025-03-05 17:23 Tshaxz 阅读(514) 评论(0) 推荐(0)
摘要: 单哈希 以下是字符串哈希的 C++ 代码模板,基于 ​多项式滚动哈希​ 实现,支持快速计算子串哈希值,适用于子串匹配、重复检测等问题: #include <vector> #include <string> using namespace std; class StringHash { privat 阅读全文
posted @ 2025-03-05 11:44 Tshaxz 阅读(68) 评论(0) 推荐(0)
摘要: 1, 2 通用模板 #include <iostream> #include <random> int main() { // 第一步:初始化真随机种子(使用硬件熵源) std::random_device rd; // 第二步:选择高性能引擎(推荐 mt19937) std::mt19937 ge 阅读全文
posted @ 2025-03-04 22:04 Tshaxz 阅读(108) 评论(0) 推荐(0)
摘要: 对数换底公式 C++17以下不能直接求log2(),需要用换底公式 $ \log_b a = \frac{\ln a}{\ln b}$ C++17及以上可以直接用log2()函数 完整实例 #include <iostream> #include <cmath> int main() { doubl 阅读全文
posted @ 2025-03-04 21:23 Tshaxz 阅读(654) 评论(0) 推荐(0)
Language: HTML