小小小松
小小小松
全部文章
分类
归档
标签
去牛客网
登录
/
注册
小小小松的博客
全部文章
(共14篇)
题解 | 数组分组 0-1背包解决分组问题
#include <bits/stdc++.h> using namespace std; bool canAchieveTarget(vector<int>& nums, int target) { if(nums.size()==0) return ta...
2025-03-26
0
28
题解 | 字符串通配符 简单代码解决掉
#include <bits/stdc++.h> #include <cctype> using namespace std; int main() { string input1, input2; cin >> input1 >> ...
2025-03-20
0
2
题解 | 24点游戏算法 C++解法
#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; bool DFS(const vector<do...
2025-03-19
0
38
题解 | 识别有效的IP地址和掩码并进行分类统计 感觉处理的相当麻烦
#include <iostream> #include <string> #include <vector> #include <sstream> #include <bitset> using namespace std; int A...
2025-03-11
0
24
题解 | 树查找,简洁高效——所有完全二叉树的题都可以当数组题来做
#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int n; while (cin >> n)...
2025-02-20
0
47
题解 | 查找第K小数
#include <iostream> #include <vector> #include <unordered_set> #include <algorithm> using namespace std; // 分区操作 int partitio...
2025-02-20
0
46
题解 | 哈夫曼树,巨通俗易懂,简洁高效
#include <iostream> #include <queue> using namespace std; // 自定义比较函数,用于优先队列(最小堆) struct myCompare { bool operator()(const int& a,...
2025-02-19
0
39
题解 | 二次方程计算器 | 人麻了
人麻了,思路很简单清晰,但写起来 代码问题一堆。思路:等式输入进字符串中,根据+ = -这些符号把多项式等式拆分成每个多项式项,例如 2x^2, 3x ,-4 。然后对这些项计算二次项系数a,一次项系数b,常数项系数c,利用求根公式得到结果。但实际在拆分的时候边界条件还是非常麻烦,但最后求出a,b,...
2025-02-14
0
42
题解 | 八皇后——实现了N皇后,可以套用模板,输入n=8即可;
经典回溯问题:N皇后。把N皇后的代码背下来,修改修改即可。解法:定义全局变量boardSize,用来控制棋盘大小,此处boardSize=8另外写了一个init()函数,用来构造8*8的棋盘。其他思路完全同N皇后,定义string path来存放一次成功的摆放方案,vector<string&...
2025-02-14
0
56
题解 | 字符串排序, 注意小坑
这题有个坑的地方是,每组数据第一行的数字后面有个小空格,不能直接定义n,然后cin>>n,这样后面执行getline(cin,s);就会把一个小空格输入到s中。所以输入n的时候也要getline(cin,input),然后定义stringstream ss(input)对象,ss>...
2025-02-14
0
51
首页
上一页
1
2
下一页
末页