自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(57)
  • 收藏
  • 关注

原创 linux c 多线程互斥锁

beers.c#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <pthread.h>int beers = 2000000;// 创建互斥锁,互斥锁对所有可能发生冲突的线程可见,是一个全局变量.// PTHREAD_MUTEX_INITIALIZER实际上是一个宏

2021-02-17 19:41:41 198

原创 python argparse

# -*- coding: utf-8 -*-# https://zhuanlan.zhihu.com/p/138294710# 上述链接讲的很透彻,重点看 8.设置变量的名字或者flag# 打印指定目录下的所有目录及文件名字# 两种类型的变量# position arguments 位置变量## 位置变量必须设置;在命令行中传入的位置不能错,按照代码中加入parser的先后顺序传入.# optional arguments 可选变量## 必须用一条或者两条短线-作为前缀;对于程序运行不是

2020-11-14 19:05:03 170

原创 error: conversion from ‘std::vector<int>::const_iterator {aka __gnu_cxx::__normal_iterator<const int

const vector作为函数形参时,要使用迭代器,必须用const_iterator,否则编译不通过。报错如下:error: conversion from ‘std::vector<int>::const_iterator {aka __gnu_cxx::__normal_iterator<const int*, std::vector<int> >}’ to non-scalar type ‘std::vector<int>::iterator {

2020-10-27 19:38:17 5488 2

原创 Ubuntu16.04 配置使用vscode

目录1.安装2.有图标但无法打开vscode3.无法在线安装插件1.安装安装过程很简单,不再赘述。安装之后使用 Ctrl加+ 放大页面,Ctrl加- 缩小页面。2.有图标但无法打开vscode参考 https://blog.csdn.net/liuxiaodong400/article/details/883135113.无法在线安装插件参考 https://zhuanlan.zhihu.com/p/124750181安装插件需要sudo权限,使用sudo打开vscode,之后在插件库中直

2020-10-06 15:59:34 288

原创 extern关键字详解☆

参考文献:https://www.runoob.com/w3cnote/extern-head-h-different.html上述参考文献中讲解很清楚。extern int a; // 声明全局变量a (声明一般放在头文件中,需要时include该头文件即可)int a; // 定义全局变量a (定义放在源文件中)extern int a = 0; // 定义全局变量并赋初值int a = 0; // 定义全局变量并赋初值对变量而言,如果你想在本源文件(例如文件名A.c)中使用另一个源文件(

2020-09-08 20:41:34 139

原创 import matplotlib.pyplot as plt

#!/usr/bin/env python#-*- coding: utf-8 -*-import mathimport randomimport numpy as npimport matplotlib.pyplot as pltimport matplotlib.patches as mpathesfrom wrTXT import ReadDataTxtdef test_01(): x = np.linspace(0, 10, 40) plt.figure(

2020-07-15 23:16:03 11013

原创 基于matplotlib.pyplot画任意函数的图像

2020高考数学 理科一卷 导数题#!/usr/bin/env python#-*- coding: utf-8 -*-import numpy as npimport matplotlib.pyplot as plt# 画任意函数的图像# 指定函数表达式def function(x): return (x + 0.5 * np.power(x, 3) + 1 - np.power(np.e, x))/(x**2)# 生成 data ydef generate_y_from_x(

2020-07-07 23:23:00 899

原创 no matching function for call to std::basic_ofstream char ::open(std::__cxx11::basic_stringstream

报错:no matching function for call to ‘std::basic_ofstream<char>::open(std::__cxx11::basic_stringstream<char>::__string_type, const openmode&)’ outfile_fit.open(ss.str(), ios::out);解决办法: stringstream ss; ss << root_path

2020-06-17 22:34:30 1365

原创 vector erase和remove

本文参考:https://blog.csdn.net/xzymmd/article/details/83652726vector.erase(pos) //移除iterator位置pos上的元素,返回下一元素的位置erase操作传入迭代器,迭代器所指位置在删除前后不发生改变,改变的只是容器中元素值。删除该元素后,被删元素后面的所有元素前移,尾部迭代器也移动到新的尾部位置。删除特定元素示例:vector<int> abc = {6,9,8,7,6,6,5,4,3,3,2,1,3};pr

2020-05-22 01:19:41 249

原创 C++类实例化与智能指针

声明:本文参考了references中列的文章,并加以整理总结。指针的值是对象的地址,指针可以看做一个存放地址值的整型。类实例化类实例化的两种方式#include<iostream>#include<cstring>#include<string>using namespace std;class C {public: C(string s = "", int i = 0, double d = 1.0) { dataMem

2020-05-21 15:17:05 2800

原创 python编程 package中__init__.py文件的作用

详细解释:https://mp.weixin.qq.com/s/5RW_wd1J9RsyX99Zbm_G0g总结:当 import 一个 Package 的时候,它会隐性的去执行此文件, 而在此文件中定义的对象,会被绑定到当前的命名空间里面来。在 Python3.2 版本之前,定义的 Package 下面一定要有此文件,这样 Python 才知道它是一个 Package,才可以寻找到相关模块的路径从而被 import。综上,这个 init 文件会在 import 的时候被执行,而空的init文件在

2020-05-14 10:23:34 207

原创 ubuntu16.04安装cajviewer 报错`GLIBCXX_3.4.22' not found

在官网下载 CAJViewer for linuxhttp://cajviewer.cnki.net/download.html下载得到的文件是 CAJViewer-x86_64-libc-2.24.AppImage, 添加执行权限sudo chmod a+x this_file运行方式,在终端直接输入以下指令即可运行./CAJViewer-x86_64-libc-2.24.AppImage如果报错./CAJViewer-x86_64-libc-2.24.AppImage: /usr.

2020-05-12 23:12:43 728

原创 动态规划 leetcode 968. 监控二叉树

题目:https://leetcode-cn.com/problems/binary-tree-cameras//** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(...

2020-05-06 19:02:51 494

原创 cmake 模块的使用和自定义模块

参考《cmake教程》第9讲:https://blog.csdn.net/lizhifeng2009/article/details/8820150一、使用FindCURL模块目录树 (没有编译,所以build文件夹为空)CMakeLists.txtcmake_minimum_required(VERSION 2.8)project(CURLTEST)add_subdirecto...

2020-04-30 23:58:17 848

原创 C++调用C语言编译的库 undefined reference to 'xxxx '

参考: https://blog.csdn.net/weixin_42005205/article/details/80417022问题:C++调用C语言编译的库,cmake 没问题,make时出现 undefined reference to 'xxxx '报错。解决办法:修改链接库的头文件, 将C++需要调用的所有C函数声明放入如下区域:#ifdef __cplusplusextern...

2020-04-29 19:49:10 567

原创 C++数据类型取值范围

参考:https://blog.csdn.net/mmk27_word/article/details/84378346https://blog.csdn.net/yohjob/article/details/89085623注意:long 等价于 long int, 这里的int可以省略。64位操作系统,long 8字节; 32位操作系统,long 4字节;long long 为8字...

2020-04-27 12:24:57 399

原创 BFS 树的层次遍历

团灭leetcode 树的层次遍历问题,层次遍历本质就是BFS广度优先搜索,在前文https://blog.csdn.net/weixin_43976833/article/details/105740752的基础上稍加改动即可完成。leetcode 102. 二叉树的层序遍历题目:https://leetcode-cn.com/problems/binary-tree-level-order...

2020-04-27 11:48:25 491

原创 BFS 广度优先搜索 二叉树的最小深度 打开转盘锁

BFS参考:https://mp.weixin.qq.com/s/WH_XGm1-w5882PnenymZ7g题目:https://leetcode-cn.com/problems/minimum-depth-of-binary-tree//** * Definition for a binary tree node. * struct TreeNode { * int val...

2020-04-24 22:02:01 164

原创 DFS leetcode 1020. 飞地的数量

题目:https://leetcode-cn.com/problems/number-of-enclaves/思路:从四条边上的1进行DFS,把与其相连接的1全部置为0,最后剩下的1就都是飞地class Solution {public: //给定索引是否在数组内 bool inArea(vector<vector<int>>& A, int...

2020-04-23 23:26:36 167

原创 DFS深度优先搜索 岛屿问题 涂色问题 扫雷游戏

题目:https://leetcode-cn.com/problems/number-of-islands/参考:https://leetcode-cn.com/problems/number-of-islands/solution/dao-yu-shu-liang-by-leetcode/基于DFS解决问题 :为了求出岛屿的数量,我们可以扫描整个二维网格。如果一个位置为 1,则以其为起...

2020-04-21 00:32:02 410

原创 动态规划 leetcode 343. 整数拆分 (同剪绳子)

题目:https://leetcode-cn.com/problems/integer-break/同剪绳子:https://leetcode-cn.com/problems/jian-sheng-zi-lcof/1. 把当前整数 i 分成 j、i-j两段,其中 1 <= j <= i-1. 2. 某种切割方式下,最大乘积 = max(两段都不剪,两段都剪,一段剪一段不剪) ...

2020-04-18 22:15:07 175

原创 动态规划 leetcode 面试题47. 礼物的最大价值

题目:https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/class Solution {public: int maxValue(vector<vector<int>>& grid) { int m = grid.size(); int n = g...

2020-04-18 15:28:07 225

原创 leetcode 42. 接雨水

接到雨水的面积 = 总面积 - 柱子的面积 - 左边没有水的面积 - 右边没有水的面积class Solution {public: int trap(vector<int>& height) { int n = height.size(); if(n == 0) return 0; int res = 0; ...

2020-04-18 13:53:19 101

原创 leetcode 445. 两数相加2

官方题解class Solution {public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { stack<int> s1, s2; while (l1) { s1.push(l1 -> val); l1 = l1 -&g...

2020-04-14 18:46:20 79

原创 leetcode 10. 正则表达式匹配

参考:https://labuladong.gitbook.io/algo/dong-tai-gui-hua-xi-lie/dong-tai-gui-hua-zhi-zheng-ze-biao-da题目:https://leetcode-cn.com/problems/regular-expression-matching/'.' 匹配任意单个字符, 一一对应。'*' 匹配零个或多个前面的那...

2020-04-11 18:42:41 144

原创 团灭leetcode股票买卖问题

参考:https://labuladong.gitbook.io/algo/dong-tai-gui-hua-xi-lie/tuan-mie-gu-piao-wen-ti状态:1. 哪一天,2. 允许交易的最大次数,3. 当前的持有状态(持有/没有持有)。选择:买入,卖出,无操作for 状态1 in 状态1的所有取值: for 状态2 in 状态2的所有取值: for...

2020-04-09 19:40:58 158

原创 团灭leetcode打家劫舍问题

参考:https://labuladong.gitbook.io/algo/dong-tai-gui-hua-xi-lie/qiang-fang-zi///打家劫舍1 leetcode 198//状态:当前房子index. 选择:抢或者不抢// dp数组定义:dp[i] 表示从第i间开始抢, 能抢到的最多的钱.// dp[i] = max(抢i, 不抢i) = max(nums[i] + ...

2020-04-09 00:50:25 189

原创 动态规划 高楼扔鸡蛋

leetcode 887 鸡蛋掉落https://leetcode-cn.com/problems/super-egg-drop/主要参考:https://labuladong.gitbook.io/algo/dong-tai-gui-hua-xi-lie/gao-lou-reng-ji-dan-wen-ti状态: 当前拥有的鸡蛋数量 K 和需要测试的楼层数N。可能你会觉得楼层区间是 [f...

2020-04-07 23:05:03 301

原创 LeetCode 13: 罗马数字转整数 C++实现

思路【转载】构建一个字典记录所有罗马数字子串,注意长度为2的子串记录的值是(实际值 - 子串内左边罗马数字代表的数值)。这样一来,遍历整个 s的时候判断当前位置和前一个位置的两个字符组成的字符串是否在字典内,如果在就记录值,不在就说明当前位置不存在小数字在前面的情况,直接记录当前位置字符对应值。举个例子,遍历经过 IV 的时候先记录 I 的对应值 1 再往前移动一步记录 IV 的值 3,加...

2020-04-05 00:02:17 129

原创 剑指offer 6. 重建二叉树

根据前序遍历序列得到根节点在中序遍历序列中定位根节点,区分开左右子树依据长度划分出左、右子树的前序遍历序列和中序遍历序列,通过递归,分别建立左右子树。/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; *...

2020-04-04 23:49:33 68

原创 剑指offer 26. 复杂链表的复制

逐个复制节点,cloned节点在源节点之后,形如A A B B C C;针对cloned节点,设置其random指针;将长链表拆分成两个链表。struct RandomListNode { int label; struct RandomListNode *next, *random; RandomListNode(int x) : lab...

2020-04-04 15:59:56 82

原创 剑指offer 45. 圆圈中最后剩下的数字

普通解法:环形链表class Solution {public: int LastRemaining_Solution(int n, int m) { if(n < 1 || m < 1) return -1; list<int> numbers; for(int i = 0;i < n;i++) {...

2020-04-03 00:37:33 263

原创 剑指offer 37. 两个链表的第一个公共结点

求两个链表的长度指向长链表的指针 先走 (long_list_len - short_list_len) 步两个指针同时运动class Solution {public: unsigned int getListLen(ListNode *head) { unsigned int len = 0; ListNode* ptr = head; ...

2020-04-02 01:17:05 110 1

原创 剑指offer 17. 合并两个排序的链表

采用迭代的方法,参考了合并两个排序数组的做法class Solution {public: ListNode* Merge(ListNode* pHead1, ListNode* pHead2) { ListNode* curr1 = pHead1; ListNode* curr2 = pHead2; ListNode* newH...

2020-04-01 23:21:01 66

原创 剑指offer 16. 反转链表

采用迭代方式反转链表class Solution {public: ListNode* ReverseList(ListNode* pHead) { ListNode* pReversedHead = NULL; ListNode* curr = pHead; ListNode* pPrev = NULL; while(c...

2020-04-01 21:23:36 81

原创 剑指offer 15. 链表中倒数第k个节点

双指针法,注意边界条件class Solution {public: ListNode* FindKthToTail(ListNode* pListHead, unsigned int k) { if(pListHead == NULL || k < 1) return NULL; ListNode* slow,* fast...

2020-04-01 17:24:32 64

原创 LeetCode92. 反转链表2 (反转从m到n的位置)

参考https://labuladong.gitbook.io/algo/shu-ju-jie-gou-xi-lie/di-gui-fan-zhuan-lian-biao-de-yi-bu-fenclass Solution {public: //反转链表前n个节点 ListNode* new_head_next; ListNode* reverseN(ListNod...

2020-03-31 23:01:16 265

原创 剑指offer 05.从尾到头打印链表

使用stackclass Solution {public: vector<int> printListFromTailToHead(ListNode* head) { vector<int> res; stack<ListNode*> nodes; ListNode* pNode = head;...

2020-03-31 01:03:28 73

原创 剑指offer 05.替换空格

原地操作,从后往前操作class Solution {public: string replaceSpace(string s) { int ori_size = s.size(); int blank_nums = 0; for(auto i:s) { if(i==' ') bla...

2020-03-29 00:40:45 73

原创 leetcode202 快乐数

核心思想:使用快慢指针思想找出循环,参考“环形链表”题目class Solution {public: int bitSquareSum(int n) { int sum = 0; while(n > 0) { int bit = n % 10; sum += pow(bit, 2); ...

2020-03-25 12:19:54 122

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除