
C++
焰与光
有问题请加企鹅630853319
个人博客正在建设中:leenzw.cn
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
OpenGL画一个雪花
void display(void){ //这是我们自己的绘图函数,我们在这里进行具体地绘制。} int main(int argc, char** argv)//main函数{ glutInit(&argc, argv); //对GLUT进行初始化,必须一开始就初始化 glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); //设置显示方式,参数之后再解释 glutInitWindowPosition(100, 100原创 2021-11-10 16:21:12 · 2758 阅读 · 0 评论 -
数据结构复习:最小生成树与KMP
最小生成树生成树:一个连通无向图的生成子树,同时要求是树。也即在图的边集中选择n - 1条,将所有顶点连通我们定义无向连通图的最小生成树为边权和最小的生成树/0—/--------------------------------------------------------------------------------------------------------------------------------------------------------------------------原创 2020-12-22 22:36:49 · 297 阅读 · 0 评论 -
基础排序专题(从插入选择到快排分治)
快速排序#include<bits/stdc++.h>using namespace std;void QuickSort(vector<int> &nums, int l, int r){ if(l + 1 >= r) return; int fir = l; int last = r; int key = nums[fir];//第一个数为基准数 while(fir < last){ while(fir < last &原创 2020-12-20 23:30:35 · 271 阅读 · 0 评论 -
图论基础例题及模板
图的存储、邻接表#include<bits/stdc++.h>using namespace std;typedef struct node{ int st; int en;}node1;vector<int>a[100010];int vis[100010]={0};void dfs(int x){ vis[x] = 1; cout<<x<<' '; for(int i = 0;i < a[x].size();i++){ i原创 2020-11-28 23:57:04 · 317 阅读 · 0 评论 -
树的基础习题模板
三种遍历、迭代实现前序遍历、根左右class Solution {public: vector<int> preorderTraversal(TreeNode* root) { vector<int>ans; if(root == NULL) return ans; stack<TreeNode*>s; s.push(root); while(!s.emp原创 2020-10-18 22:17:56 · 250 阅读 · 0 评论 -
【长期更新】STL相关例题
LeetCode 128.最长连续序列class Solution {public: int longestConsecutive(vector<int>& nums) { unordered_set<int> hash; for(const int& num : nums) hash.insert(num);//将nums中数遍历加入至哈希表中 int ans = 0;原创 2020-10-12 21:50:06 · 225 阅读 · 0 评论 -
简单计算器模拟
虽然打个简单计算器不算难事,但是模拟始终算一关,不能忽视基础。本程序不适用以下情况:表达式中带空格表达式中带括号仅能进行四则运算,结果限制在int型#include<bits/stdc++.h>using namespace std;int level(char x){ if(x == '+' || x == '-') return 1; else return 2;}int calculate(string s){ s原创 2020-10-02 23:19:32 · 1547 阅读 · 0 评论 -
Leetcode 101刷题记录(4)
633.平方数之和class Solution {public: bool judgeSquareSum(int c) { if(c == 0 || c==1) return 1; long x1 = 0; long x2 = sqrt(c); while(x1 != x2){ long t1 = x1 * x1; long t2 = x2 * x2;原创 2020-09-23 19:33:53 · 133 阅读 · 0 评论 -
Leetcode 101刷题记录(5)
695. 岛屿的最大面积class Solution {public: int dir[4][2] = {-1,0,0,-1,1,0,0,1};//gird.size()表示x轴方向上长,gird[0].size表示y轴方向上 int maxAreaOfIsland(vector<vector<int>>& grid) { if(grid.empty() || grid[0].empty()) return 0;原创 2020-09-10 23:08:14 · 144 阅读 · 0 评论 -
Leetcode 101刷题记录(3)
167.两数之和class Solution {public: vector<int> twoSum(vector<int>& numbers, int target) { int in1 = 0,in2 = numbers.size() - 1; for(;;){ if(numbers[in1] + numbers[in2] > target) in2--;原创 2020-08-31 23:22:27 · 171 阅读 · 0 评论 -
Leetcode 101刷题记录(2)
605.种花问题class Solution {public: bool canPlaceFlowers(vector<int>& flowerbed, int n) { int size = flowerbed.size(); int cnt = 0; flowerbed.insert(flowerbed.begin(),0); flowerbed.insert(flowerbed.end(),0);//在两边原创 2020-08-29 22:38:45 · 154 阅读 · 0 评论 -
Leetcode 101刷题记录(1)
本文大部分内容来自同名刷题题解,以及加上一些个人的理解与注释。455.分发饼干class Solution {public: int findContentChildren(vector<int>& g, vector<int>& s) {//child and cookie sort(g.begin(),g.end()); sort(s.begin(),s.end()); int child = 0;原创 2020-08-27 18:33:37 · 306 阅读 · 0 评论