上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 33 下一页
摘要: C++ 类型转换 C++ 中的类型转换是指将一种数据类型的值转换为另一种数据类型。C++ 提供了隐式类型转换和显式类型转换两种方式,另外引入了更安全和可控的 C++ 风格的类型转换。 隐式类型转换 编译器自动完成的类型转换,主要发生在以下情况: 算术运算中不同类型的转换 int a = 10; do 阅读全文
posted @ 2025-05-19 22:58 _Sylvan 阅读(88) 评论(0) 推荐(0)
摘要: C++ 函数指针 函数指针是 C++ 中一种保存函数地址的指针变量,允许像调用普通函数那样通过指针调用函数。它是理解回调机制、策略模式、以及 C/C++ 中函数灵活性的基础。 返回类型 (*函数指针名)(参数类型列表); int add(int a, int b) { return a + b; } 阅读全文
posted @ 2025-05-19 19:44 _Sylvan 阅读(30) 评论(0) 推荐(0)
摘要: inline 关键字 内联函数 C++ 中的 内联函数(inline function) 是一种用于提升小函数执行效率的技术,通过在编译阶段将函数调用处替换为函数体代码,从而避免函数调用带来的开销(如压栈、跳转等)。 inline 返回类型 函数名(参数列表) { // 函数体 } 减少函数调用开销 阅读全文
posted @ 2025-05-19 17:31 _Sylvan 阅读(88) 评论(0) 推荐(0)
摘要: 函数声明与函数定义 概念 函数声明 告诉编译器函数的名称、返回类型、参数类型及(可选的)参数名,以便在调用处进行类型检查、布局调用约定等。通常放在头文件(.h)或源文件顶部。 返回类型 函数名(参数类型1 参数名1, 参数类型2 参数名2, …); // math_utils.h int add(i 阅读全文
posted @ 2025-05-19 15:24 _Sylvan 阅读(107) 评论(0) 推荐(0)
摘要: 贪心6 1921. 消灭怪物的最大数量 #include <cstdio> #include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int eli 阅读全文
posted @ 2025-05-16 23:09 _Sylvan 阅读(11) 评论(0) 推荐(0)
摘要: 贪心5 45. 跳跃游戏 II #include <vector> #include <algorithm> using namespace std; class Solution { public: int jump(vector<int> &nums) { int n = nums.size() 阅读全文
posted @ 2025-05-16 21:40 _Sylvan 阅读(12) 评论(0) 推荐(0)
摘要: 贪心4 1675. 数组的最小偏移量 #include <iostream> #include <vector> #include <set> using namespace std; class Solution { public: // 返回数组执行某些操作后可以拥有的最小偏移量 int min 阅读全文
posted @ 2025-05-16 18:50 _Sylvan 阅读(12) 评论(0) 推荐(0)
摘要: 贪心3 581. 最短无序连续子数组 #include <vector> #include <algorithm> #include <limits> using namespace std; class Solution { public: static int findUnsortedSubar 阅读全文
posted @ 2025-05-16 16:52 _Sylvan 阅读(10) 评论(0) 推荐(0)
摘要: 贪心2 LCR 132. 砍竹子 II #include <iostream> using namespace std; class Solution { public: const int MOD = 1e9 + 7; // 快速幂算法,计算 (x^n) % mod long long power 阅读全文
posted @ 2025-05-16 00:44 _Sylvan 阅读(17) 评论(0) 推荐(0)
摘要: 贪心1 179. 最大数 #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class Solution { public: // 暴力方法生成所有可能的 阅读全文
posted @ 2025-05-15 21:08 _Sylvan 阅读(21) 评论(0) 推荐(0)
摘要: 动态规划中根据数据量猜解法 打怪兽 a[i] 范围大,b[i] 范围小的适用版本 #include <iostream> #include <vector> #include <climits> #include <algorithm> using namespace std; // 方法1:a[i 阅读全文
posted @ 2025-05-15 15:25 _Sylvan 阅读(17) 评论(0) 推荐(1)
摘要: 动态规划中得到具体决策方案 最长公共子序列 #include <iostream> #include <vector> #include <string> using namespace std; // 最大字符串长度 const int MAXN = 5001; // dp[i][j] 表示 s1 阅读全文
posted @ 2025-05-15 13:16 _Sylvan 阅读(8) 评论(0) 推荐(0)
摘要: 动态规划中优化枚举 1235. 规划兼职工作 #include <iostream> #include <vector> #include <algorithm> using namespace std; class Solution { public: int jobScheduling(vect 阅读全文
posted @ 2025-05-14 23:07 _Sylvan 阅读(24) 评论(0) 推荐(1)
摘要: C++ 左值右值 左值(lvalue):有名字、有地址的对象,能出现在赋值号左边 右值(rvalue):没有名字、临时存在的值,只能出现在赋值号右边 如何判断 能否被赋值? 能否取地址? 类型 能 能 左值 不能 不能(大部分情况) 右值 int x = 42; &x; // 左值能取地址 &(x 阅读全文
posted @ 2025-05-14 18:42 _Sylvan 阅读(61) 评论(0) 推荐(0)
摘要: const 关键字 修饰变量 当 const 用于普通变量时,它表示该变量的值在初始化后不能被修改。 const int x = 10; x = 20; // 错误,不能修改常量变量 const int arr[3] = {1, 2, 3}; arr[0] = 4; // 错误,不能修改数组内容 修 阅读全文
posted @ 2025-05-14 18:42 _Sylvan 阅读(63) 评论(0) 推荐(0)
上一页 1 ··· 11 12 13 14 15 16 17 18 19 ··· 33 下一页