自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

紫魔戒

思绪来的快,去的也快,偶尔在这里停留

  • 博客(40)
  • 收藏
  • 关注

原创 半小时学会LevelDB原理及应用

LevelDBLevelDB之概览  LevelDB是Google传奇工程师Jeff Dean和Sanjay Ghemawat开源的KV存储引擎。   了解原理之前首先要用起来,下面动手实现个例子:安装调试(mac上直接命令行下brew install leveldb即可安装,编译时候记得加上-lleveldb)   example:#include <assert.h>#include <s

2017-09-22 15:57:00 40458 5

原创 什么是隔离见证?简单介绍隔离见证

每一个比特币交易,都可以分为两部分。第一部分是转账记录,第二部分是用来证明这个交易合法性(主要是签名)的。第一部分可称为“交易状态”,第二部分就是所谓的见证(witness)。如果你只关心每个账户的余额,那么转账记录就已经足够了。只有部分人(主要是矿工)才有必要取得交易见证。 (交易信息就是谁给谁在什么时间转了多少钱。 见证信息就是哪个节点在什么时间验证交易信息的可靠性。)中本聪在设计比特币的时

2017-07-24 15:35:19 2863

原创 区块链定义

区块链定义 1、区块链由许多对等的结点组成,通过共识算法保证区块数据和交易数据的一致性,从而形成一个统一的分布式账本。 从技术层面来看,区块链是一个基于共识机制、去中心化的公开数据库 共识机制是指在分布式系统中保证数据一致性的算法; 去中心化是指参与区块链的所有结点都是权力对等的,没有高低之分; 公开数据库则意味着所有人都可以看到过往的区块和交易,这也保证了无法造假和改写2、从价值层面来看,

2017-07-21 05:41:15 1148

原创 Proving NP-completeness

Proving NP-completeness by generalization. For each of the problems below, prove that it is NP-complete by showing that it is a generalization of some NP-complete problem we have seen in this chapter.

2017-06-30 19:49:44 696

原创 椭圆曲线ECC基本概念

椭圆曲线的曲线方程是以下形式的三次方程: y2+axy+by=x3+cx2+dx+ey^2+axy+by=x^3+cx^2+dx+e a,b,c,d,e是满足某些简单条件的实数。定义中包含一个称为无穷点的元素,记为O 如果其上的3个点位于同一直线上,那么它们的和为O O为加法单位元,即对ECC上任一点P,有P+O=PP+O=P 设P1=(x, y)是ECC上一点,加法逆元定义为P2=

2017-06-26 10:57:08 944

转载 进程死锁及解决办法

进程死锁及解决办法一、要点提示(1) 掌握死锁的概念和产生死锁的根本原因。(2) 理解产生死锁的必要条件–以下四个条件同时具备:互斥条件、不可抢占条件、占有且申请条件、循环等待条件。(3) 记住解决死锁的一般方法,掌握死锁的预防和死锁的避免二者的基本思想。(4) 掌握死锁的预防策略中资源有序分配策略。(5) 理解进程安全序列的概念,理解死锁与安全序列的关系。(6) 了解银行家算法。(7) 了解资源分

2017-06-25 21:44:45 1112

转载 sqrt函数实现(神奇的算法)

我们平时经常会有一些数据运算的操作,需要调用sqrt,exp,abs等函数,那么时候你有没有想过:这个些函数系统是如何实现的?就拿最常用的sqrt函数来说吧,系统怎么来实现这个经常调用的函数呢?虽然有可能你平时没有想过这个问题,不过正所谓是“临阵磨枪,不快也光”,你“眉头一皱,计上心来”,这个不是太简单了嘛,用二分的方法,在一个区间中,每次拿中间数的平方来试验,如果大了,就再试左区间的中间数;如果小

2017-06-25 18:59:52 61241 15

原创 LeetCode207. Course Schedule

DescriptionThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed

2017-06-19 16:43:01 261

原创 封装、继承、多态详解

封装、继承、多态(1)封装  封装,也就是把客观事物封装成抽象的类,并且类可以把自己的数据和方法只让可信的类或者对象操作,对不可信的进行信息隐藏。(2)继承  继承是指这样一种能力:它可以使用现有类的所有功能,并在无需重新编写原来的类的情况下对这些功能进行扩展。    继承现有类 + 扩展继承概念的实现方式有三类:实现继承、接口继承和可视继承。 实现继承是指使用基类的属性和方法而无需

2017-06-09 14:40:49 3065

原创 LeetCode532. K-diff Pairs in an Array

DescriptionGiven an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both

2017-06-08 19:37:46 320

原创 LeetCode300. Longest Increasing Subsequence

DescriptionGiven an unsorted array of integers, find the length of longest increasing subsequence. For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3,

2017-05-30 20:20:18 187

原创 LeetCode581. Shortest Unsorted Continuous Subarray

DescriptionGiven an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You need

2017-05-26 18:15:46 187

原创 如何实现守护进程?

守护进程(Daemon)是运行在后台的一种特殊进程。它独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件。守护进程是一种很有用的进程。 1、守护进程最重要的特性是后台运行。 2、守护进程必须与其运行前的环境隔离开来。这些环境包括未关闭的文件描述符,控制终端,会话和进程组,工作目录以及文件创建掩模等。这些环境通常是守护进程从执行它的父进程(特别是shell)中继承下来的。 3、守护进程

2017-05-25 12:01:32 11265

原创 C++中substr函数的用法

substr用法basic_string substr( size_type pos = 0, size_type count = npos ) const; Returns a substring [pos, pos+count). If the requested substring extends past the end of the string, or if count == np

2017-05-22 14:24:21 1318

原创 LeetCode560. Subarray Sum Equals K

DescriptionGiven an array of integers and an integer k, you need to find the total number of continuous subarrays whose sum equals to k. Example 1: Input:nums = [1,1,1], k = 2 Output: 2 Note

2017-05-21 19:51:26 282

原创 各种排序算法C++

各种排序算法插入排序直接插入排序void InsertSort(int arr[], int len) { int i, j; int temp; for (i = 1; i < len; i++) { temp = arr[i]; for (j = i - 1; j >= 0 && arr[j] > temp; j--)

2017-05-21 16:57:44 439

原创 LeetCode566. Reshape the Matrix

DescriptionIn MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a t

2017-05-20 19:31:17 241

原创 LeetCode 128. Longest Consecutive Sequence

DescriptionGiven an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Given [100, 4, 200, 1, 3, 2], The longest consecutive elements sequence is

2017-05-15 15:17:18 222

原创 # 线程安全 & 线程安全函数 & 线程不安全函数

线程安全 & 线程安全函数 & 线程不安全函数  线程安全 就是多线程访问时,采用了加锁机制,当一个线程访问该类的某个数据时,进行保护,其他线程不能进行访问直到该线程读取完,其他线程才可使用。不会出现数据不一致或者数据污染。   如果每次运行结果和单线程运行的结果是一样的,而且其他的变量的值也和预期的是一样的,就是线程安全的。   一个类或者程序所提供的接口对于线程来说是原子操作或者多个线程之间

2017-05-15 07:12:57 2207

原创 Linux进程状态

Linux进程状态Linux内核中的进程状态◆运行状态(TASK_RUNNING) 指正在被CPU运行或者就绪的状态。这样的进程被成为runnning进程。运行态的进程可以分为3种情况:内核运行态、用户运行态、就绪态。◆可中断睡眠状态(TASK_INTERRUPTIBLE) 处于等待状态中的进程,一旦被该进程等待的资源被释放,那么该进程就会进入运行状态。◆不可中断睡眠状态(TASK_UN

2017-05-13 10:11:11 194

原创 C++ 4种强制类型转换

C++的四种强制类型转换为:static_cast、const_cast、reinterpret_cast和dynamic_cast 类型转换的一般形式:cast-name(expression);static_cast任何具有明确定义的类型转换,只要不包含底层const,都可以使用static_cast; double slope = static_cast(j) / i;注:

2017-05-10 07:17:33 302

原创 TCP超时重传、滑动窗口、拥塞控制、快重传和快恢复

TCP超时重传  原理是在发送某一个数据以后就开启一个计时器,在一定时间内如果没有得到发送的数据报的ACK报文,那么就重新发送数据,直到发送成功为止。   影响超时重传机制协议效率的一个关键参数是重传超时时间(RTO,Retransmission TimeOut)。RTO的值被设置过大过小都会对协议造成不利影响。   (1)RTO设长了,重发就慢,没有效率,性能差。   (2)RTO设短了,重

2017-05-08 19:33:07 6187 1

原创 LeetCode 69. Sqrt(x)

DescriptionImplement int sqrt(int x). Compute and return the square root of x.my program 思路:看似很简单的问题,可以不断的优化算法,最开始容易想到的是定义一个num使其递增,直到num*num > x,可是未考虑num*num越界的问题,后更改判断条件为num <= x/num,可以消除越界问题。但是此算

2017-05-07 20:25:05 248

原创 LeetCode543. Diameter of Binary Tree

DescriptionGiven a binary tree, you need to compute the length of the diameter of the tree. The diameter of a binary tree is the length of the longest path between any two nodes in a tree. This path ma

2017-05-04 12:56:40 270

原创 LeetCode119. Pascal's Triangle II

DescriptionGiven an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].my programclass Solution {public: vector<int> getRow(int rowIndex) { ve

2017-04-23 22:15:00 202

原创 HTTP与HTTPS异同||HTTP1.0与HTTP1.1差别

HTTP状态码 分类 解释 描述 1XX 信息 服务器收到请求,需要请求者继续执行操作 2XX 成功 操作被成功接收并处理 3XX 重定向 需要进一步的操作以完成请求 4XX 客户端错误 请求包含语法错误或无法完成请求 5XX 服务器错误 服务器在处理请求的过程中发生了错误常见的状态码 状态代码 状态消息 描述 2

2017-04-19 15:08:09 1952

原创 TCP三次握手四次挥手

TCP三次握手四次挥手 标志位缩写 全称 中文 SYN synchronous 建立联机 ACK acknowledgement 确认 PSH push 传送 FIN finish 结束 RST reset 重置 URG urgent 紧急 Seq Sequence number 顺序号码 ACK

2017-04-18 21:25:53 194

原创 LeetCode447. Number of Boomerangs

DescriptionGiven n points in the plane that are all pairwise distinct, a “boomerang” is a tuple of points (i, j, k) such that the distance between i and j equals the distance between i and k(the order

2017-04-16 17:50:41 262

原创 LeetCode406. Queue Reconstruction by Height Add to List

DescriptionSuppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in fron

2017-03-31 16:40:17 179

原创 LeetCode455. Assign Cookies

DescriptionAssume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum siz

2017-03-26 23:54:12 167

原创 LeetCode 34. Search for a Range

DescriptionGiven an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If th

2017-03-19 20:11:35 258

原创 int abs(int number)函数有感: 求补码和通过补码求对应的整数 C++(增加:数字的二进制表示中1的个数)

#include "limits.h"#include "math.h"int abs(int number){ int const mask = number >> (sizeof(int) * CHAR_BIT - 1); return (number + mask) ^ mask;}  这是一个求绝对值的函数,看了它不禁想起负数在计算机中的构成.   负数在计算机中是按

2017-03-12 16:06:35 1503

原创 LeetCode: 338. Counting Bits

338. Counting BitsDescriptionGiven a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array

2017-03-11 11:53:37 238

原创 vector--C++ STL 学习

vector–C++ STL 学习vector对应的数据结构为数组,而且是动态数组,也就是说我们不必关心该数组事先定义的容量是多少,它的大小会动态增长。与数组类似的是,我们可以在末尾进行元素的添加和删除,也可以进行元素值的随机访问和修改。   vector是STL中最常见的容器,它是一种顺序容器,支持随机访问。vector是一块连续分配的内存,从数据安排的角度来讲,和数组极其相似.   不

2017-03-05 21:36:09 251

原创 LeetCode 53. Maximum Subarray

53. Maximum Subarraymy program:class Solution {public: int maxSubArray(vector<int>& nums) { int result = nums[0]; int sum = 0; for (int i = 0; i<nums.size(); ++i) {

2017-03-01 12:54:02 320

原创 map--C++ STL 学习

map–C++ STL 学习  Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在map中出现一次,第二个可能称为该关键字的值)的数据处理能力。   说下map内部数据的组织,map内部自建一颗红黑树(一种非严格意义上的平衡二叉树),这颗树具有对数据自动排序的功能,所以在map内部所有的数据都是有序的。 map是使用红黑树实现的,访问、查找和删除操作的复杂度都

2017-02-26 17:19:43 318

原创 LeetCode 371.Sum of Two Integers

LeetCode 371.Sum of Two Integers

2017-02-25 19:09:32 243

原创 LeetCode459. Repeated Substring Pattern

今天在做C语言经典实例100题中遇到的一题,其中的方法很值得学习,第一种是我自己所编写的程序,方法很一般,是个人都能想到。而第二种方法则非常巧妙。 32题目:删除一个字符串中的指定字母,如:字符串 “aca”,删除其中的 a 字母。#include <stdio.h>#include <string.h>int main(){ char str[100]; char c;

2016-06-02 15:03:44 235

原创 2016.05.31

学习《C专家编程》序言中的编程挑战中,解决对#include 1.time_t是long的typedef形式;2.函数ctime()描述 C 库函数char **ctime(const time_t *timer)返回一个表示当地时间的字符串,当地时间是基于参数 timer。 返回的字符串格式如下: Www Mmm dd hh:mm:ss yyyy其中,Www表示星期几,

2016-05-31 21:33:42 269

转载 欢迎使用CSDN-markdown编辑器

欢迎使用Markdown编辑器写博客本Markdown编辑器使用[StackEdit][6]修改而来,用它写博客,将会带来全新的体验哦:Markdown和扩展Markdown简洁的语法代码块高亮图片链接和图片上传LaTex数学公式UML序列图和流程图离线写博客导入导出Markdown文件丰富的快捷键快捷键加粗 Ctrl + B 斜体 Ctrl + I 引用

2016-05-31 20:39:59 166

空空如也

空空如也

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

TA关注的人

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