自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 链接时报错undifined symbo:_ZNxxx定位

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入欢迎使用Markdown编辑器你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar

2021-09-27 21:49:35 566

原创 vs中使用第三方库的方法

debug模式步骤如下: 首先,注意所给的库是64位的还是32位的,将平台与所给的库的平台保持一致。 (1) 工程下面新建一个“DLL”文件夹,将第三方库所需的头文件拷贝过来,然后在“DLL”文件夹中新建两个文件夹,命名分别为“debug”和“release”,在这两个文件夹中放对应“debug”和“release”版本的第三方lib文件和dll文件; 如下图所示: (2) 打开项目属性

2017-01-19 16:01:09 5541

原创 计算机系应届生找C/C++工作参考书籍及经验(博主已拿腾讯offer)

1.《C++ premier》 2.《Effective C++》 3.《More Effective C++》 4.《深度探索C++对象模型》:其中多态实现机制一定要搞懂。 5.《STL源码剖析》:重点看。 6.《剑指offer》:重点看,里面有很多算法问的频率比较高。 7.《王道程序员求职宝典》:重点看,里面有很多基础知识也常问到。 8. 计算机网络里面问到TCP三次握手和四次握手

2016-12-02 14:37:27 3437 4

原创 把二叉树打印成多行

题目:从上到下按层打印二叉树,同一层的结点按从左到右的顺序打印到一行。 分析:为了把二叉树的每一行单独打印到一行里,我们需要两个变量:一个变量表示在当前层中还没有打印的结点数,另一个变量表示下一层结点的数目。struct BinaryTreeNode{ int value; struct BinaryTreeNode *left; struct BinaryTreeNode

2016-09-17 16:20:24 544

原创 正则表达式的匹配

模式中的字符’.’表示任一字符,而‘*’表示它前面的字符可以出现任意次(含0次)。在本题中,匹配是指字符串的所有字符匹配整个模式。例如,字符串“aaa”与模式“a.a”和“ab*ac*a”匹配,但与“aa.a”及“ab*a”均不匹配。分析:分两种情况 a). 当模式中的第二个字符不是’*’时问题要简单很多。如果字符串中的第一个字符和模式中的第一个字符相匹配,那么在字符串和模式上都向后移动一个字符,

2016-09-16 21:49:11 437

原创 不用算术运算符实现两个数的加法。

(1)先不考虑进位,按位计算各位累加(用抑或实现),得值a; (2)然后计算进位,并将进位的值左移,得值b,若b为0,则a就是加法运算的结果,若b不为0,则a+b即得结果(递归调用该函数);int add_no_arithm(int a, int b){ if (0 == b) return a; //当没有进位时 int sum = a^b; int carry = (

2016-08-25 11:03:06 1688

原创 m阶B+树与m阶B树的主要差异在于:

在B+树中,具有n个关键字的结点只含有n棵子树,即每个关键字对应一棵子树;而在B树中,具有n个关键字的结点含有(n+1)棵子树。在B+树中,每个结点(非根结点)关键字个数n的范围是[m/2向上取整,m](根结点:1<=n<=m),在B树中,每个结点(非根结点)关键字个数n的范围是[m/2向上取整-1,m-1](根结点:1<=n<=m-1)。在B+树中,叶结点包含信息,所有非叶结点仅起到索引作用,

2016-08-04 11:45:18 4089

原创 自定义类如何使用multiset进行排序

关键点:自定义类需要重载”<”运算符,并且 重载的函数”operator<”参数(如果传的是引用)和函数的类型都要为const。如果参数是非const对象的引用,则会报如下错误:二进制“<”: 没有找到接受“const Interval”类型的右操作数的运算符(或没有可接受的转换)(如果参数非引用,则不会报此错误);如果函数非const,则会报如下错误:二进制“<”: 没有找到接受“const In

2016-07-15 10:03:46 2900

原创 最小的k个数

输入n个整数,找出其中最小的k个数。例如输入4、5、1、6、2、7、3、8这8个数字,则最小的4个数字是1、2、3、4。 解法一: 基于partion函数来解决这个问题。如果基于数组的第k个数字来调整,使得比第k个数字小的所有数字都位于数组的左边,比第k个数字大的所有数字都位于数组的右边。这样调整之后,位于数组中左边的k个数字就是最小的k个数字(这k个数字不一定是排序的)。 C++代码:#in

2016-07-14 19:27:19 865

原创 求一组数的所有组合。

**算法思路:**n个数能够构成长度为1的组合、长度为2的组合、……、长度为n的组合。在求n个数的长度为m(m>=1 && m<=n)的组合时,我们把这n个数分成两部分:第一个数和其余的所有数。如果组合里包含第一个数,则下一步在剩余的数中选取m-1个数;如果组合里不包含第一个数,则下一步在剩余的n-1个数中选取m个数。这两个子问题都可以用递归的方式解决。#include <iostream>#in

2016-07-14 16:42:50 2639

原创 几种常见的排序算法实现

1. 插入排序//插入排序#include <iostream>using namespace std;//每次遍历将第i个数插入到前i-1个数中(前i-1个数已排好序)void insertSort(int a[], int n){ for (int i=1;i<n;++i) { int tmp = a[i]; int j;

2016-07-12 20:55:50 432

原创 二叉树的前序、中序、后序的递归与非递归遍历算法实现

看代码一目了然。 C++代码:#include <iostream>#include <stack>#include <queue>using namespace std;//二叉树节点typedef struct BitNode{ char data; BitNode *lchild; BitNode *rchild;}BitNode, *BiTree;//按先

2016-07-12 12:31:34 8091 3

原创 LeetCode第60题之Permutation Sequence

思想:给定数字n和k后,则(n-1)!表示最高一位固定是可表示的排列的种树,例如,当n=3时:“123” “132” “213” “231” “312” “321” 最高位分别为1,2,3,时都对应两种排列情况。,当k=1、2时,最高位为1,当k=3、4时,最高位为二,当k=5、6时,最高位为3。由规律可知,最高位=(k-1)/(n-1)!+1。 第二位第三位依次类推。 下面给出C+

2016-07-01 22:01:25 429

原创 一种用C++自带的类生成服从正态分布的随机数。

今天写关于深度学习的代码时,里面要用服从标准正态分布的随机数初始化权值,就是matlab里面那个randn函数,网上找了很多方法,最后发现C++本身就有自带的方法生成服从正态分布的随机数序列。下面给出C++代码: C++代码:#include <iostream>#include <string>#include <random>#include <iomanip>//设置精度#inclu

2016-06-30 19:02:28 12457

原创 LeetCode第56题之Merge Intervals

思路: 这题不难,先将区间进行“排序”,然后便历每个区间(下面代码中的cur)看是否与前面的区间(下面代码中的tmp)重合。分如下两种情况: (1) 如果重合,将tmp和cur区间合并为一个区间(更新tmp.end); (2) 如果不重合,则tmp为一个合并后的区段,保存tmp。 然而,我做这题的时候开始没有用将compare函数申明为static,然而运行不通过,通过百度之后发现

2016-06-29 16:23:56 390

原创 LeetCode第54题之Spiral Matrix

这题题的长和宽不等,所以有可能出现某一圈中有上边没有下边或者有右边没有左边的情况,因此在代码中我在相应位置加入了两个if语句来判断是否是上面的情况(某一圈中有上边没有下边或者有右边没有左边)。 C++代码:#include <iostream>#include <vector>using namespace std;class Solution {public: vector<int

2016-06-28 12:47:59 312

原创 大整数的相加、相减和相乘

#include <iostream>#include <string>using namespace std;string _sub(string s1, string s2);//比较两个正数的大小inline int compareData(const string &s1,const string &s2){ if (s1.length()>s2.length()) ret

2016-06-28 12:29:41 567

原创 LeetCode第53之 Maximum Subarray(两种方法)

解法一: 思路:最大子段和max_sum必是以某个下标为i的数结尾,遍历数组,如果当前子段和tmp_sum大于等于0,则nums[i]+tmp_sum一定不会比nums[i]小。#include <iostream>#include <vector>#include <limits>using namespace std;class Solution {public: int ma

2016-06-27 20:48:11 605

原创 LeetCode第51题之 N-Queens

思路主要是参考我以前的一篇博客:8皇后问题的两种解法,那篇博客思路写的还比较详细,建议看那篇博客。这里我只用第一种解法实现该题。 下面给出C++源代码:#include <iostream>#include <string>#include <vector>using namespace std;class Solution {public: //检查在第k个位置的皇后是否与前k-

2016-06-25 13:09:29 259

原创 LeetCode第50.之Pow(x, n)

运用递归解,另外注意n的各种取值的情况。 C++代码:#include <iostream>#include <limits>using namespace std;class Solution {public: double myPow(double x, int n) { if (0 == n) return 1; else

2016-06-25 09:43:52 232

原创 LeetCode第49题之 Group Anagrams

分析:这道题如果按照 常规的思路几层for循环暴力求解会超时。这里我主要是利用将每个待处理的字符串排序后用哈希的思想将同构的字符串放在一起。 C++代码:#include <iostream>#include <algorithm>#include <string>#include <map>#include <vector>using namespace std;class Solut

2016-06-24 15:29:07 374

原创 LeetCode第47.题之Permutations II

这题和上一题唯一的差别是数组多了重复的元素,所以我首先想到的是STL中计算排列组合关系的算法(这是我以前写的一篇博客)(该算法也适合上一题),具体思想见那篇博客,下面我直接给出C++代码:#include <iostream>#include <algorithm>#include <vector>using namespace std;class Solution {public:

2016-06-23 21:56:32 229

原创 LeetCode第46题之 Permutations

主要的思想(深度优先搜索)和我这篇博客一样:找出1到n所有不重复的排列,即n的全排列#include <iostream>#include <algorithm>#include <vector>using namespace std;class Solution { void fun(vector<int> &nums, vector<bool> &appear, vector<in

2016-06-23 20:21:35 288

转载 LeetCode第45之 Jump Game II

看了好几种算法实现,感觉这里说的最清楚,也比较简单,本算法思想也是来源于此。 解法看完这道题目,可能大部分的读者都能够想出这样一个相对简单的解法:将每个位置都看作一个点,并从第i个点向它之后的nums[i]个点都连一条长度为1的有向边,而现在的问题就是从0号点到达size-1号点需要的最短距离,这就是一个很简单的最短路问题,实际上由于边的长度均为1,而且不存在环,我们可以用宽度优先搜索(时间复杂度

2016-06-23 19:24:43 1143

原创 LeetCode第44题之 Wildcard Matching

思想主要参考这里,但那里是用char *保存的字符串,该字符串最后以’\0’字符结尾,故上述代码中p字符串不会越界。而现在字符串是用的string保存,需要讨论p字符串的下标是否越界。 C++代码:#include <iostream>#include <string>#include <vector>using namespace std;class Solution {public:

2016-06-22 18:41:48 345

原创 LeetCode 43题之 Multiply Strings

详细的算法思路参见我以前的一篇博客:大整数相乘 C++代码:#include <iostream>#include <string>#include <vector>using namespace std;class Solution {public: //将原字符处转换成数组存放 vector<int> stoint(const string &s) {

2016-06-21 19:15:33 258

原创 LeetCode第42题之Trapping Rain Water

下面C++代码只需一遍遍历,具体分析见代码注释:#include <iostream>#include <vector>using namespace std;class Solution {public: int trap(vector<int>& height) { int sum = 0; int n = height.size();

2016-06-21 15:11:21 361

原创 LeetCode第40题之Combination Sum II

这一题主要是在上一题的基础上解决重复解的问题。 C++代码:#include <iostream>#include <algorithm>#include <vector>using namespace std;class Solution {private: //res保存满足题意的结果 vector<vector<int>> res; //保存当前的一种方案

2016-06-20 19:17:34 348

原创 LeetCode第39题之Combination Sum(两种方法)

思路:两种方法都是利用递归回溯,第二方法在第一种方法的基础上对原始数据先进行排序,这样可以剪枝,加快计算速度。第一种方法在LeetCode上测试运行的时间是24ms,第二种方法运行时间为16ms。 方法一:#include <iostream>#include <algorithm>#include <vector>using namespace std;class Solution {p

2016-06-18 12:27:00 681

原创 LeetCode第37之Sudoku Solver

主要思路:回溯法,每个‘.’的位置遍历“1-9”,如果满足则继续下一个位置,如果遍历完“1-9”仍不满足则将该位置改为‘.’,然后回溯到上一个位置。 缺点就是运行时间有点长。 C++代码:#include <iostream>#include <vector>using namespace std;//打印board矩阵void print_vec(vector<vector<char>>

2016-06-17 11:39:48 220

原创 LeetCode第34题之Search for a Range

C++代码:#include <iostream>#include <vector>using namespace std;class Solution {public: vector<int> searchRange(vector<int>& nums, int target) { vector<int> res(2, -1); int sz = nu

2016-06-16 15:40:07 353

原创 LeetCode第33题之 Search in Rotated Sorted Array

C++代码:#include <iostream>#include <vector>using namespace std;class Solution {public: int search(vector<int>& nums, int target) { int sz = nums.size(); int l = 0; int r =

2016-06-15 19:48:44 241

转载 32. Longest Valid Parentheses

主要参考:http://blog.csdn.net/feliciafay/article/details/20686595,该方法的时间复杂度为O(n)。 C++代码:class Solution { public: int longestValidParentheses(string s) { stack<int> paranStack; int

2016-06-14 20:27:57 238

原创 LeetCode第29题之Divide Two Integers

C++代码:#include <iostream>#include <limits>using namespace std;class Solution {public: int divide(int dividend, int divisor) { //将int转换成long long int可以省事,例如当被除数与除数分别为-2147483648、 1时,21474

2016-06-08 11:13:48 327

原创 LeetCode第26题之Remove Duplicates from Sorted Array

C++代码:#include <vector>#include <iostream>using namespace std;class Solution {public: int removeDuplicates(vector<int>& nums) { //j遍历数组,如果nums[j]在位置j之前第一次出现,则将它保存到i+1的位置 int sz =

2016-06-06 10:20:47 263

原创 LeetCode第25题之Reverse Nodes in k-Group

基本思想是对每k个节点采用头插法,时间复杂度为O(n)。 C++代码:#include <vector>#include <iostream>using namespace std;/** * Definition for singly-linked list. */ struct ListNode { int val; ListNode *next;

2016-06-04 13:22:12 249

原创 LeetCode第23题之Merge k Sorted Lists

C++代码:#include <vector>#include <iostream>#include <algorithm>using namespace std;/** * Definition for singly-linked list. */ struct ListNode { int val; ListNode *next; ListNode

2016-06-03 20:27:00 319

原创 LeetCode第21题之Generate Parentheses(两种解法)

C++代码:#include <vector>#include <iostream>#include <string>using namespace std;class Solution {private: //保存结果 vector<string> res;public: void fun(int deep, int n, int leftNum, int lef

2016-06-02 11:28:54 431

原创 LeetCode第20题之Valid Parentheses

方法一:用栈实现 C++代码:#include <stack>#include <iostream>using namespace std;//Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.class S

2016-05-31 09:15:17 361

原创 LeetCode第19题之 Remove Nth Node From End of List

Given a linked list, remove the nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked list be

2016-05-30 21:39:10 294

空空如也

空空如也

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

TA关注的人

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