自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(61)
  • 资源 (1)
  • 收藏
  • 关注

转载 循环有序数组/旋转数组的二分查找

转载于 http://blog.sina.com.cn/s/blog_a2498b5b01014bsg.html类似问题:循环有序数组/旋转数组的最小值 《剑指offer》P66#include using namespace std;int binarySearch(int a[],int low,int high,int value) //二分查找{ if(low

2016-10-18 21:44:42 721

原创 背包问题

#include using namespace std;// 参考 http://baike.baidu.com/link?url=kOn5J1ionfV40_l4SagPK3aO6vu6TAB4r9iPociRXEm6R0Er8JEb4wpE2_53GJe8vPQ-KLb8-Au6r3N4K8h6PDpxqMhyEkxWxZoFWcqlqfZhZJCjuFTVixTVbZx1Fzu7

2016-10-12 12:38:30 321

原创 打印1到最大的n位数

#include #include using namespace std;// 参考《剑指offer》P94bool increment_number(char *number){ int take_over = 0; int len = strlen(number); for (int i = len - 1; i >= 0; --i){ int sum = n

2016-10-11 14:44:39 285

原创 最近共同祖先

#include #include using namespace std;// 参考 http://blog.csdn.net/cxllyg/article/details/7635992// 参考 《剑指offer》P256struct node{ int data; node *left; node *right; node(const int &x, nod

2016-10-10 15:24:09 599

转载 sql查询关键词的书写顺序与执行顺序

参考 http://www.cnblogs.com/Jessy/p/3527091.html查询中用到的关键词主要包含六个,并且他们的书写顺序为select--from--where--group by--having--order by其中select和from是必须的,其他关键词是可选的,这六个关键词的执行顺序与书写顺序并不是一样的,执行顺序为from-

2016-09-13 22:20:23 7403 2

原创 整数转字符串

#include #include using namespace std;int main(){ int i = 12345; int max_length = 80; char *chars = new char[max_length]; sprintf(chars, "%i", i); string str = string(chars); int t

2016-09-09 21:03:24 349

原创 字符串转整数

#include #include using namespace std;int myAtoi(string str) { string s = str; int index = 0; bool flag = true; if (str.size() == 0){ return 0; } while (s[index]

2016-09-09 20:54:42 218

原创 死锁

死锁条件互斥条件(Mutual exclusion):资源不能被共享,只能由一个进程使用。请求与保持条件(Hold and wait):已经得到资源的进程可以再次申请新的资源。非剥夺条件(No pre-emption):已经分配的资源不能从相应的进程中被强制地剥夺。循环等待条件(Circular wait):系统中若干进程组成环路,该环路中每个进程都在等待相邻进程正占用的资源。

2016-09-08 22:01:02 295

转载 简析TCP的三次握手与四次分手

转载于 http://www.jellythink.com/archives/705三次握手第一次握手:建立连接。客户端发送连接请求报文段,将SYN位置为1,Sequence Number为x;然后,客户端进入SYN_SEND状态,等待服务器的确认;第二次握手:服务器收到SYN报文段。服务器收到客户端的SYN报文段,需要对这个SYN报文段进行确认

2016-09-08 15:19:53 1695

原创 python yield和generator

def fab(max): n, a, b = 0, 0, 1 while n < max: yield b # print b a, b = b, a + b n = n + 1# for n in fab(5):# print nf = fab(5)print f.next()print f.next()print f.next()print f.nex

2016-06-02 18:16:44 363

转载 HTTP状态码

http://www.w3school.com.cn/tags/html_ref_httpmessages.asp1xx: 信息消息:描述:100 Continue服务器仅接收到部分请求,但是一旦服务器并没有拒绝该请求,客户端应该继续发送其余的请求。101 Switching Protocols服务

2016-05-20 21:00:51 369

原创 读入一行以空格隔开的参数

#include #include #include #include using namespace std;//读入一行以空格隔开的参数//1. 用getline从控制台读入一行//2. 利用istringstream对象绑定一行字符串//这种方式可以免去手动切割字符串的复杂操作,解决了while (cin >> s)无法终止循环的问题int main(){ stri

2016-05-19 13:18:12 1438

原创 输入输出运算符重载

#include #include using namespace std;//输入输出流运算符重载有两点需要注意//1. 函数参数要用引用,primer上是这样解释的:不用引用的话就是按值传递,而iostream规定是不允许拷贝其副本的,所以必须要用引用//2. 函数返回值应当是函数参数中输入输出流的引用,这是为了适用于连续输入输出的情形,具体见下面的例子//参考 http://b

2016-05-19 12:52:52 483

原创 函数模板隐式调用时的优先级

#include #include using namespace std;//当函数模板隐式调用时,若同时存在模板函数和非模板函数,优先匹配非模板函数templateinline void foo(T a) { cout << "in template\t" << a << endl;}inline void foo(int a) { cout << "in speci

2016-05-19 11:19:17 641

转载 二叉树的非递归遍历

参考http://www.cnblogs.com/dolphin0520/archive/2011/08/25/2153720.html 的5楼回复#include #include using namespace std;struct Node { int data; Node *left; Node *right; Node(int d, Node *l

2016-05-13 23:30:05 259

原创 虚函数的内存结构

//参考http://www.cnblogs.com/Ripper-Y/archive/2012/05/15/2501930.html//参考http://blog.csdn.net/haoel/article/details/1948051/#include using namespace std;class base { virtual void f(){ cout<<"base

2016-05-13 22:58:54 362

原创 图的实现、无向图的最小生成树、有向图的最短路径

graph.h#ifndef __GRAPH__#define __GRAPH__#include #include using namespace std;class DisjointSet;template class Graph {public: virtual bool insert(int u, int v, TypeOfEdge weight) = 0;

2016-05-06 23:08:59 4233 1

原创 函数模板与类模板

参考http://blog.csdn.net/csw_100/article/details/5844615#include using namespace std;template void func(T a){ cout << a << endl;}template class A{public: A(T a):data(a){} T data;

2016-05-03 19:33:14 338

原创 重载、覆盖、重写(隐藏)

#include #include using namespace std;/*参考http://www.cnblogs.com/itech/archive/2010/06/04/1751532.htmlOverload(重载):在C++程序中,可以将语义、功能相似的几个函数用同一个名字表示,但参数或返回值不同(包括类型、顺序不同),即函数重载。(1)相同的范围(在同一个类中);

2016-04-30 21:08:15 597

原创 大小端判断

#include #include using namespace std;int main(){ //小端 数据高字节保存在内存高地址,地址由大向小增长 //对以下两种方法,小端输出4 3 2 1 //方法1 union { int i; char c[sizeof(int)]; }un; un.i = 0x01020304; cout

2016-04-30 13:35:22 378

转载 字节对齐

转自http://www.jb51.net/article/41436.htm3条原则:(在没有#pragma pack宏的情况下)1. 数据成员对齐规则:结构(struct)(或联合(union))的数据成员,第一个数据成员放在offset为0的地方,以后每个数据成员存储的起始位置要从该成员大小或者成员的子成员大小(只要该成员有子成员,比如说是数组,结构体等)的整数倍开始(比

2016-04-30 13:14:47 215

原创 初始化列表

#include #include using namespace std;//必须使用初始化列表的四种情况//参考http://www.cnblogs.com/graphics/archive/2010/07/04/1770900.html//1. 常量成员class A{public: A(int x):a(x){} const int a;};//2. 引用成

2016-04-30 12:01:00 415

原创 STL map的遍历与pair的使用

#include #include using namespace std;int main(){ //map的遍历 unordered_map a; a[1] = 4; a[3] = 5; a[2] = 6; for (unordered_map::iterator it = a.begin(); it != a.end(); ++it){ cout fi

2016-04-24 17:26:19 2482 1

原创 函数调用运算符的重载

#include #include using namespace std;#if 1class st{public: //重载+运算符 void operator+(int i){ cout << "override +:\t"<< i << endl; } //重载()运算符(函数调用运算符, 与一般运算符的使用方式有所不同) //重载了函数调用运算符,

2016-04-24 15:24:34 708

原创 函数指针与function对象

《effective C++》p171-p174#include #include using namespace std;//function对象( 也可直接写作typedef function my_func; )typedef tr1::function my_func;//函数指针typedef void (*my_func_2)(int);void fun

2016-04-24 14:50:36 441

原创 C和C++的读入方式对比

#include #include #include using namespace std;int main(){ //读一行 string s; getline(cin, s); char ch[80]; cin.getline(ch, 80); char ch2[80]; gets(ch2); //读一个字符 char a = cin.get(

2016-04-23 15:14:19 294

原创 C++ split

#include #include #include using namespace std;//find函数寻找完整匹配,find_first_of函数寻找任一匹配//http://www.cnblogs.com/mumuliang/archive/2009/11/20/1873571.htmlvector split(string s, string delim){ vect

2016-04-23 14:32:06 817

转载 C++组合与继承

两篇文章http://www.cnblogs.com/whitewolf/archive/2010/05/03/1726519.htmlhttp://www.cnblogs.com/liuling/archive/2013/05/01/extends.html

2016-04-21 11:16:06 481

原创 const static

#include using namespace std;class A{public: int data; //const成员的初始化必须在构造函数初始化列表中初始化,不可以在构造函数函数体内初始化 const int const_data; //static成员的初始化或赋值不能在类的内部 static int static_data; //只有静态常量整

2016-04-20 12:13:04 259

原创 C++单例

#include #include #include #include using namespace std;//单例类只能有一个实例//单例类必须自己创建自己的唯一实例//单例类必须给所有其他对象提供这一个实例//C++单例class Singleton{private: static Singleton *instance; Singleton(){}pu

2016-04-20 12:11:58 252

原创 指针常量与常量指针

#include using namespace std;int main(){ int x = 1; int y = 2; //指针常量(指针的值不能修改,指向的内容可以修改) int * const p = &x; //const修饰p //p = &y; //误 *p = 3; //常量指针(指向常量的指针,指针的值可以修改,指向的内容不能修改)

2016-04-16 16:41:50 189

原创 快速排序链表

时间复杂度O(N*logN),空间复杂度O(1)参考 http://www.cnblogs.com/TenosDoIt/p/3666585.html//依据快速排序METOHD_3的思想//取第一个元素作为枢纽元//链表范围是[low, high)#include using namespace std;struct ListNode { int val;

2016-04-10 11:49:21 233

原创 数字字符串是否为合法IP地址

以下代码亟待改进#include #include using namespace std;bool check_range(string s){ int i = stoi(s); if (i >= 0 && i <= 255) return true; return false;}void find_valid(string s, string re

2016-04-09 18:08:05 531

原创 归并排序链表

时间复杂度O(N*logN),空间复杂度O(1)参考 http://www.cnblogs.com/TenosDoIt/p/3666585.html#include using namespace std;struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL)

2016-04-09 17:17:32 323

原创 堆排序

这里基于循环实现,还可以基于递归实现,递归实现可参考《算法导论》#include using namespace std;void percolate_down(int *a, int hole, int size){ int tmp = a[hole]; int child; while (hole * 2 + 1 < size){ child = ho

2016-04-09 15:38:27 265

原创 C++ string 与 C char *

#include #include using namespace std;//C++ string 操作 http://www.cplusplus.com/reference/string/string///C++ string 类型转换 http://www.cplusplus.com/reference/string///C char * 操作 http:

2016-04-08 13:01:10 424

转载 进程间通信

# 信号 ( sinal ) : 信号是一种比较复杂的通信方式,用于通知接收进程某个事件已经发生。# 信号量( semophore ) : 信号量是一个计数器,可以用来控制多个进程对共享资源的访问。它常作为一种锁机制,防止某进程正在访问共享资源时,其他进程也访问该资源。因此,主要作为进程间以及同一进程内不同线程之间的同步手段。# 消息队列( message queue ) : 消息队列是由

2016-04-04 16:09:26 406

原创 打印回形矩阵

打印一个回形矩阵如下1 2 3 412 13 14 511 16 15 610 9 8 7#include //当n=4时,分别打印1-3, 4-6, 7-9, 10-12, 每次打印(n-1)个数,第一圈打完后打第二圈//n为奇数时,可刚好打完;n为偶数时剩最后一个数int a[10][10]; //最大支持边长10的矩阵,其他情况可用动态

2016-04-04 10:41:46 2726

原创 引用传参与指针传参

#include using namespace std;void swap_quote(int &a, int &b){ int tmp = a; a = b; b = tmp;}void swap_pointer(int *a, int *b){ int tmp = *a; *a = *b; *b = tmp;}int main(){ int a

2016-04-02 16:26:09 311

原创 全排列问题、八皇后问题、组合问题的递归解法

全排列问题#include using namespace std;void swap(char *a, char *b){ char tmp = *a; *a = *b; *b = tmp;}void find_core(char* col, char* begin){ if (*begin == '\0'){ cout << col << endl;

2016-04-01 19:49:44 1038

BDRateComputation

该表格实现了HEVC测试序列的BDRate计算,使用中开启excel宏即可

2014-04-12

空空如也

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

TA关注的人

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