自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 木棒切割问题

《算法笔记》第134页 问题:给出N根木棒长度已知但不一定相等, 现在希望通过切割得到长度相等的K根木棒,求长度相等的K根木棒最长是多少? 如:给3根木棒,长度为10, 24, 15,要切割得到7根长度相等的木棒, 则7根木棒的长度最长为6,其组合为1*6+4*6+2*6。 暴力解法: #include<cstdio> const int maxn=10010; int ma...

2018-07-21 19:02:47 3959 3

原创 温故知新:中序线索二叉树(thread binary tree)

  线索二叉树是在二叉树的基础上改进得到的,在原有的二叉树结点中添加两个变量分别用来记录该结点的左右孩子是否线索化。struct threadBinaryTreeNode { elementType number; dataType data; threadBinaryTreeNode<elementType,dataType> *lchild,*rchild;...

2018-05-13 19:22:17 284

原创 温故知新:二叉树(binary tree)的实现

这儿给出树的实现及四种遍历方式,若有错误,欢迎指出。首先,定义树结点,template<typename dataType,typename elementType> struct treeNode { elementType info; dataType data; treeNode<dataType,elementType> *lchild,*r...

2018-05-09 16:36:39 163

原创 温故知新:合并排序(merge sort)及优化方法

在学习数据结构的表时,我们经常会做到这样的一道题:将两个数组合并为一个数组,并且从低位到高位是非减的。这题不难,但这样的操作是合并排序的基本过程。合并排序的基本思想是分治,将整个的数组排序建立在其子数组的排序之上,其过程为,将数组a[1~n]划分为以单个元素为一个集合,这样就得到了n个集合,再两两集合进行合并的同时排序(就是上面提到的那道题的操作),合并完就得到了n/2(取上整)个集合,再重复合并...

2018-05-05 10:02:48 2195

原创 温故知新:快速排序算法(quick sort)及优化

快速排序快速排序算法的基本思想是在数组a[0~n]中找一个元素a[r]作为划分点,在a[r]右边的数组都小于该划分点,在a[r]左侧的数组都大于该划分点,然后再在a[0~r-1]和a[r+1~n]重复该步骤。template<typename T> void quickSort_plus(T a[],int l,int r){ if(l>=r) return ; ...

2018-05-01 13:09:21 173

原创 PAT :反转链表

题目链接:https://www.patest.cn/contests/pat-b-practise/1025给定一个常数K以及一个单链表L,请编写程序将L中每K个结点反转。例如:给定L为1→2→3→4→5→6,K为3,则输出应该为3→2→1→6→5→4;如果K为4,则输出应该为4→3→2→1→5→6,即最后不到K个元素不反转。 输入格式: 每个输入包含1个测试用例。每个测试用例第1行给出第1...

2018-03-20 13:37:55 277

原创 PAT:数字黑洞

题目链接:https://www.patest.cn/contests/pat-b-practise/1019#include <iostream> #include<algorithm> using namespace std; class Solution{ public: static bool Cmp(char a,char b){ r...

2018-03-18 11:55:03 230

原创 整数(1~3999)转化为罗马数字

Given an integer, convert it to roman.Input is guaranteed to be within the range from 1 to 3999.class Solution { public: string intToRoman(int num) { char symbol[]={'I','V','X','L','C','D'...

2018-03-04 13:21:37 546

原创 罗马数字转化为整数(1~3999)

Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999class Solution { public: int romanToInt(string s) { if(s.size() == 0) return 0; ...

2018-03-04 11:19:54 1196

原创 反转整型

Given a 32-bit signed integer, reverse digits of an integer.Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note: Assume we are dealing with an ...

2018-03-03 15:48:06 106

原创 字符串乘积

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2.Note: The length of both num1 and num2 is < 110.Both num1 and num2 contains only digits 0-9...

2018-03-03 09:49:20 213

转载 二叉树最小深度

Question:Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node./** * Definition for a binary tr...

2018-02-26 13:46:25 230

原创 合并两个排序数组

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.class Solution { public: void merge(vector<int>& nums1, int m, vector<int>& nums2,...

2018-02-25 19:26:24 295

原创 合并k个顺序链表

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *nex...

2018-02-25 16:23:10 113

转载 算法:两个排序数组的中位数

问题:给两个排序数组a和b,大小分别为n和m,求这两个排序数组的中位数,要求时间复杂度为log(n+m)。我的解法:double findMedianSortArray(int a[],int n,int b[],int m)//O(n) { int len=m+n; int* newarr=new int[len]; int i=0,p1=0,p2=0; whil...

2018-02-22 14:17:17 294

空空如也

空空如也

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

TA关注的人

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