自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Sammy Lan-Promises Don't Come Easy!

Waiting For My Princess!

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

原创 庖丁解牛之--std::bind

std::bind真是个好东西.在C++ 11之前,boost有个类似的东西boost::bind,其实现比较复杂.自从C++  11出引入模板的不定参数,右值引用(完美转发),auto等机制之后,实现就变得容易多了,本文在C++11对std::bind进行解析.

2016-04-01 15:16:35 506

原创 微软2016校园招聘9月在线笔试-题目3 : Fibonacci

题目3 : Fibonacci时间限制:10000ms单点时限:1000ms内存限制:256MB描述Given a sequence {an}, how many non-empty sub-sequence of it is a prefix of fibonacci sequence.A sub-sequence is a sequenc

2015-09-30 14:59:59 1472 1

原创 Ugly Number II

Ugly Number IIclass Solution {public: int nthUglyNumber(int n) { vec.reserve(n); vec.push_back(1); int i2 = 0; int i3 = 0; int i5 = 0; for(int i

2015-09-13 20:14:27 583

原创 Different Ways to Add Parentheses

Different Ways to Add ParenthesesGiven a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid ope

2015-07-30 15:14:17 602

原创 Palindrome Linked List

Palindrome Linked ListGiven a singly linked list, determine if it is a palindrome.Follow up:Could you do it in O(n) time and O(1) space?以下是使用Length的版本class Solution {public: bo

2015-07-27 17:12:34 552

原创 Binary Search Tree Iterator

Binary Search Tree IteratorImplement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest num

2015-07-27 16:44:51 422

原创 Kth Smallest Element in a BST

Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note: You may assume k is always valid, 1 ≤ k ≤ BST's total e

2015-07-27 16:39:52 405

原创 Search a 2D Matrix

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.

2015-07-25 15:50:02 351

原创 Sliding Window Maximum

Sliding Window MaximumGiven an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Ea

2015-07-25 15:13:20 410

原创 Min Stack

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.getMin() -- Retrieve the minimum elemen

2015-07-25 15:05:48 411

原创 Search a 2D Matrix II

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right.Integers in each column are sorted in ascending from top to bottom.

2015-07-25 14:59:04 384

原创 下雨积水问题

int Adjust(stack & s, int const cur, vector const & L){ int sum = 0; while (!s.empty() && L[cur] > L[s.top()]) { int top = L[s.top()]; s.pop(); if (!s.empty()) { sum += (min(L[s.top()],

2014-12-29 20:10:57 952

原创 [动态规划]货币发行问题

/*问题描述:货币发行问题假定你可以发行面值为1,3,5,7,9....的货币现在每天你要交一块钱给房东,房东一开始没有钱(按天结算)当然房东有钱以后可以找你钱每天都不能有拖欠现在你要交31天房租,问最少要发行多少张货币?*//*问题分析:1. 我们只在交易无法继续进行下去的时候发行货币2. 每次发行货币我们都发行面值尽可能大的货币 假设第N天已经发行的货币无法继续交

2014-09-24 15:59:43 831

原创 [动态规划] 蛇行序列(snake sequence)

You are given a grid of numbers. A snake sequence is made up of adjacent numbers such that for each number, the number on the right or the number below it is +1 or -1 its value. For example, 1 3 2

2014-09-24 11:11:23 1242

原创 判断n是否是N的整数次方(N是2的N次方)

昨天翻了下自己以前的博客,看到这样一道题:" 判断一个数是否是4的整数次方",就想能不能用模板的方式将4扩展到2,4,8,...2^n的所有情况呢?于是将题目改为:"判断n是否是N的整数次方,其中N必须是2的整数次方且大于1,如果传的N不符合规范,则编译错误"template bool isPowerOf(size_t n)以下是代码实现template struct Static

2014-09-24 10:48:10 989

原创 判断一个数是否是4的整数次方

<br />原理:<br /><br />2的整数次幂且奇数位置1的数为4分整数次幂,此算法可以扩展到求(2^n)的整数次幂,对于8的整数次幂,只需要将N-2改为N-3即可,对于16的整数次幂,需要将mask<30>改成mask<28>并将N-2改成N-4.也就是,对于(2^n)的整数次幂,我们只需要改两个地方<br />1.将mask<30>中的30改成32位整形中(2^n)最大的幂二进制表示中最高有效位的位置<br />2.将N-2改成N-n<br />template<size_t N> st

2010-09-04 15:22:00 1432 1

原创 用非静态成员函数作为线程启动函数

问题: 有没有办法让线程函数作为一个类的非静态成员函数? http://topic.csdn.net/u/20100817/20/4513b936-8269-464f-9ca5-4cdbd146a40d.html

2010-09-02 17:38:00 2308 3

原创 模板元编程:接受一个复合类型C作为第一个参数,并将其中的类型A替换为类型B

template struct type_replace; //接受一个复合类型C作为第一个参数,并将其中的类型A替换为类型B typedef type_replace :: result_type t1; // int* typedef type_replace :: result_type t2; // long* [10] typedef type_replace :: result_type t3;// long (*)(long, con

2010-09-01 21:14:00 2055 4

原创 深入理解C++对象模型-成员函数的本质以及虚函数的实现(非虚继承)

注:本文所有观点纯属推测,请勿盲目信任  前言:本文是前一篇文章的续篇,在阅读本文之前请先阅读前一篇文章>.在开始本文讨论之前,先给出一段代码,后面将基于这段代码进行讨论.//Base.h#pragma once#include using namespace std;struct Base1{ virtual int __stdcall Base1

2010-04-10 12:14:00 1650

原创 深入理解C++对象模型-对象的内存布局,vptr,vtable

前言:本文将用到另一篇文章所提供的类模板类ReinterpretCast,详细请参考文章> vtpr的位置:为了支持多态,C++引入了vtpr和vtable这两个概念.对于每个有虚函数的类,C++都会为其生成一个vtable,并在类中添加一个隐含的数据成员vptr. 对于vptr在对象中的位置,跟类的数据成员的布局一样,C++标准里面并没有做出任何的规定.但是对于特定的编译器,我们还是可以通过

2010-04-09 23:49:00 4946

原创 深入理解C++对象模型之类型转换:ReinterpretCast

 在C++中,没有任何一种转换操作符可以将成员指针转换成其它类型数据类型,那有没有办法获取到成员指针的值呢?有的人会说可以通过sprintf,atoi等函数获取.那有没有更简单通用的方法呢?答案是有的.我们可以通过template 和 union实现任何类型到另一兼容类型的(所谓兼容是指,两种类型的大小一致)转换操作符 ReinterpretCast.在给出这一实现之前,我们先来先来探讨一

2010-04-08 20:35:00 2387 1

原创 本机字节序转网络字节序的一种实现

#include using namespace std;typedef unsigned char BYTE;typedef long long LONGLONG;inline long SwapLong(const BYTE* pByte){    return (pByte[0]             (pByte[1]             (pByte

2010-02-24 12:39:00 914

原创 扩展的斐波那契数列:求兔子个数

问题描述:第1年有1对兔子,每对兔子从出生后第3个年起,就可每年生1对兔子,兔子的寿命是6年,问第n年有多少对兔子?  Normal 0 7.8 磅 0 2 false false false

2010-01-07 12:16:00 903

原创 Happy New Year

#include #include #include  int main(){      std::string str ="6666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 66666/n/6699

2010-01-01 00:46:00 971

原创 如何打印虚表和虚函数指针的值(only for VS)

#include using namespace std;typedef void (__thiscall *Func)(void*pThis); Func * GetVptr(void* pThis, int iOffset=0){         static union     {         int iVal;         Func * vptr;

2009-11-12 19:46:00 1493

原创 ...

23:21 2009-9-20:强忍着不去逛你的空间,昨天还是不争气地跑去你空间逛了一下,发现相册里面的照片没有了.心情没有想像中难受,或许是被自己折磨地太久了,麻木了...

2009-09-20 23:27:00 631

原创 巧用batch设置环境变量

我们在做开发的时候,有时候需要设置一些环境变量,比如设置第三方库的inclue路径和lib路径,以及运行时的path路径,有什么办法可以简化这些设置呢?使用batch是个不错的选择,下面是使用win batch设置环境变量的一个例子假设你有一个dev.env文件,内容如下VSINSTALL_DIR=!VS80COMNTOOLS!../..THIRDPARTY_DIR=D:/3rdP

2009-06-19 13:19:00 2248

原创 求类的数据成员的大小

前阵子点点问我一个问题:对于浦东的变量,我们可以使用sizeof(obj)来求其大小但是对于一个类的数据成员,却不能用sizeof(类名::数据成员)的方式来求其大小有没有什么办法可以实现类似的需求呢?下面是我提供的一种解决方案但是该解决方案有一个缺点,就是只能对public的数据成员求值对于private或者protected的数据成员,则只能在类

2009-06-10 16:23:00 1012

原创 用bat创建快捷方式

其实最后还是通过vbs来创建快捷方式思路:思路:通过bat输出vbs代码,然后调用WScript.exe执行相关代码 @echoset ShortcutTargetPath="%~dp0%../External/DEVENV.bat"set ShortcutPath="C:/Documents and Settings/lanx/Desktop/TCT.lnk"set Ic

2009-06-10 16:16:00 2438

原创 求一个32位无符号整数右边"0"的个数

int calc(unsigned int n){ if(0==n)  return 32; unsigned int ref=0xFFFF; unsigned int cnt=16; int sum =0; while(n>1) {  if(n&ref)  {   n&=ref;     }  else  {   sum+=cnt;

2008-06-24 20:59:00 1001

转载 我要知道我的税在哪里?

    今天就是个人申报收入超过12万元的最后期限了,我面对日历,心中充满了矛盾,不知自己是否应当去申报不要再去较真,还是应以沉默代替我的抗议。   本人收入年薪15万元,由所在的公司代扣代缴所得税,每年总计两万多元的税收贡献给了国家。税是应当交的,它是作为人民代言人的政府履行公共职责不可缺少的手段。但收税也就收了,还要口口声声要对不按时申报的人处以罚款,我不禁出离愤怒了,我们的沉默换来的

2007-04-24 14:49:00 1538

原创 螺旋输出N*N矩阵

#include #include using namespace std;void func(int n){    static const int dir[][2]={{0,1},{1,0},{0,-1},{-1,0}};    const int size=n+2;    int **ver=new int *[size];    for (int i=0;i

2007-04-24 10:06:00 1431

原创 一组方便调试的宏

//DBTrace.h#pragma once/*************************************************************************1.如果在VC6中使用该头文件,需要define VC6宏,VC6不能输出函数名,不支持long long类型*   (也就是64位整数)*2.如果需要输出函数参数,需要define _

2007-04-04 20:35:00 1339

原创 迅雷笔试题

struct Int{       short int _val;       short int _count; }; void Sort(int*ver,int const SIZE){    //ASSERT(SIZE    Int*p;    for (int i=0;i    {       p=(Int*)&ver[ver[i]&0xFFFF];

2006-11-26 09:58:00 1363

原创 面试题:求一个INT32整数里面有多少个位是置1 的

#include using  std::cout;using std::endl;using std::cin;int count(int i){    int count=0;    while (i){       ++count;       i=(i-1)&i;    }    return count;}int main(){   

2006-09-11 12:20:00 1699

原创 STL:map的使用:删除map中指定值为value的所有元素

//第一个解决方案//erase.h#include using std::find_if;   templateclass _map>class Proxy{    typename _map::mapped_type   const _value;public:    Proxy(typename _map::mapped_type const &value

2006-09-10 15:20:00 4800

原创 管道的故事

很久、很久以前,有两位名叫柏波罗和布鲁诺的年轻人,他们是堂兄弟,雄心勃勃,住在意大利的一个小村子里。 两位年轻人是最好的朋友。 他们是大梦想者。 他们不停里谈着,渴望有一天能通过某种方式,让他们可以成为村里最富有的人。他们都很聪明而且勤奋。他们想他们需要的只是机会。一天,机会来了。村里决定雇两个人把附近河里的水运到村广场的水缸里去。这份工作交给了柏波罗和布鲁诺。两个人都抓起两个水桶奔向河边。一

2006-09-10 09:37:00 1207

原创 网易面试题:求连续几个自然数之和为S的序列

#includeusing std::cout;using std::endl;void output(int const a,int const b){    cout}bool getanser(int const sum){    bool bFind=false;    int mid=(sum+1)/2;    int a=1,b=2,s=3;

2006-09-09 22:52:00 1816

原创 让静态成员函数具有多态性(浅谈如何使回调函数具有多态性)

// 在Windows编程中,经常要用到回调函数.要封装具有回调函数的对象//就将回调函数设为类的静态成员函数,而在C++中,静态成员函数是没有多态性的.//如何使静态函数具有"多态性的行为"呢,下面通过封装thread来说明这一技巧 //主要体现在static unsigned  int __stdcall ThreadProxy( void *pvParam )//和int

2006-08-11 12:54:00 1694

原创 10进制转2进制

char *Dec2Binary(unsigned int  n){    static char strBinary[sizeof(n)*8+1];    char*p=strBinary+sizeof(n)*8;    *p=/0;     while (n)    {          --p;       *p=0x30+(n&1);      

2006-08-06 00:45:00 1629

空空如也

空空如也

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

TA关注的人

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