- 博客(44)
- 资源 (13)
- 收藏
- 关注
原创 百度三面:找出数组中所有这样的数,大于等于左边的所有数,小于等于右边的所有的数
#include using namespace std;void func(int *a, int len, int &b1, int &b2){ int a1, a2; b1 = a1 = 0; b2 = a2 = len-1; int l_min, r_max; l_min = a[a1]; r_max = a[a2]; while(a1<a2) { if(a[
2013-10-16 20:43:51
692
原创 n后问题
关键问题:不在同行,同列,斜线上。即对任意两行,!(x[r1]==x[r] || abs(r1-r)==abs(x[r1]-x[r]))。用回溯法,通过此条件进行减枝。#include using namespace std;void print(int *x, int n){ int i, j; for(i=0; i<n; i++) { for(j=0; j<n; j
2013-10-06 12:57:06
669
原创 输出递增数组中和为sum的两个数
算法本身不复杂,但是提供了一个跟有序数组相关的一个思路:记录首尾指针,由两边向中间缩进。#include using namespace std;bool findPairWithSum(int* a, int len, int sum, int& n1, int& n2){ if(a==NULL || lena[len-1]+a[len-2]) return false;
2013-10-05 23:18:08
1141
1
原创 数组中的逆序对
比归并排序只多了一句输出。#include using namespace std;void getInversePair(int* a, int* b, int low, int mid, int high){ int l=low, m=mid+1, k=low, j; while(l<=mid && m<=high) { if(a[l]>a[m]) { f
2013-10-05 14:18:53
591
原创 第一个只出现一次的字符
#include using namespace std;#define min(x, y) (x)<(y)?(x):(y) char getFirstSingleChar(char* s){ if(s==NULL || *s==0) return 0; int len = strlen(s); unsigned int h_table[256] = {0}; int i
2013-10-05 13:46:56
586
原创 丑数,只包含因子2、3、5的数
#include using namespace std;#define min(x, y) (x)<(y)?(x):(y) int getUglyNumber(int index){ if(index<0) return 1; int* nums = new int[index]; nums[0] = 1; int next_id = 1; int* ugly2
2013-10-05 13:30:26
810
原创 给定一系列字符串集合,合并有交集的集合,合并完后集合之间无交集
#pragma warning(disable:4786)#include #include #include #include using namespace std; int main(){ //初始化数据 vector > v; vector v1; v1.push_back("aaa"); v1.push_back("bbb"); v1.push_b
2013-10-04 23:00:00
997
转载 memcached
基本问题1、memcached的基本设置1)启动Memcache的服务器端# /usr/local/bin/memcached -d -m 10 -u root -l 192.168.0.200 -p 12000 -c 256 -P /tmp/memcached.pid-d选项是启动一个守护进程,-m是分配给Memcache使用的内存数量,单位是MB,我这里是10MB,
2013-10-04 13:55:23
584
原创 用map求交集
#include #include using namespace std;int main(){ int a[] = {1,2,3,4,5,6,7,8,9}; int b[] = {2,4,6,8,10}; int c[10]; map m; int len_a = sizeof(a)/sizeof(a[0]); int len_b = sizeof(b)/sizeof(
2013-10-04 00:04:13
2563
原创 剑指offer-33:把数组排成最小的数
#include using namespace std;const int N = 20;char s[N][N];char com1[2*N+1];char com2[2*N+1];int comp(const void *v1, const void *v2){ strcpy(com1, (char*)v1); strcat(com1, (char*)v2); str
2013-10-03 15:37:04
592
原创 最长回文:动态规划
#include using namespace std;void huiwen(char* a){ if(a==NULL) return ; int len = strlen(a); bool table[100][100] = {false}; int max, max_id; int i,j; for(i=0; i<len; i++) table[i][i] =
2013-09-28 23:37:26
568
原创 百度笔试:最长回文(中心扩展法)
#include using namespace std;void huiwen(char* a, int& max, int& max_id){ if(a==NULL || *a=='\0') { max = 0; max_id = 0; return ; } int len = strlen(a); int i, k1, k2; max = 1; max_id
2013-09-28 23:23:40
755
原创 百度笔试:求大于n的最小的不重复数,不重复数是指相邻两个数不相同
#include using namespace std;int next_norepeat(unsigned int n){ int pow, i, j; i=++n; pow=0; while(i) { pow++; i/=10; } int *a = new int[pow+1]; a[0] = 0; for(i=pow, j=n; i>0; i--, j
2013-09-28 22:27:29
1150
原创 组合
#include #include using namespace std; //函数功能 : 从一个字符串中选m个元素//函数参数 : pStr为字符串, m为选的元素个数, result为选中的//返回值 : 无void Combination_m(char *pStr, int m, vector &result){ if(pStr == NULL ||
2013-09-27 20:21:42
565
原创 将二叉搜索树转换成双向链表
#include #include using namespace std; struct node{ int data; node* lchild; node* rchild;}; node* buildBTree(int* a, int &i){ if(a==NULL || a[i]==-1)
2013-09-27 18:56:57
598
原创 二叉树中和为某一值的路径
#include #include using namespace std; struct node{ int data; node* lchild; node* rchild;};void find_path(node* r, int exceptedSum, vector &path, int& curSu
2013-09-27 13:33:31
501
原创 打印1到最大的n位数
剑指offer用的是字符串,还要苦逼的字符串比较,看是否进位。直接用整型数组来保存。#include #include using namespace std; //一个int保存几位数const int int_num = 2;//每位数最大值,超过这个要进位(不包括最高位)const int int_max = 99; void func(){
2013-09-26 17:00:31
447
原创 链表翻转,每k个进行翻转
链表翻转。给出一个链表和一个数k,比如链表1→2→3→4→5→6,k=2,则翻转后2→1→4→3→6→5,若k=3,翻转后3→2→1→6→5→4,若k=4,翻转后4→3→2→1→5→6#include using namespace std;struct node{ int data; node* next;};node* init(int n){ n
2013-09-19 22:49:28
666
原创 利用二级指针删除节点
#include using namespace std;struct node{ int data; node* next;};void remove(node** head, int value){ if(head == NULL) return ; node** n = head; node* cur; while
2013-09-18 17:29:39
507
原创 已知先序,中序,求后序
#include using namespace std;void func(int* pre, int* mid, int pre_left, int pre_right, int mid_left, int mid_right){ if(pre_left == pre_right) { cout<<pre[pre_left
2013-09-18 16:18:10
658
原创 判断平衡二叉树,创建二叉树,先序遍历二叉树
#include using namespace std;struct node{ int data; node* lchild; node* rchild;};bool is_banance_tree(node* r, int& height){ if(r == NULL) { height = 0; retu
2013-09-17 23:58:14
523
原创 拷贝构造函数,赋值运算符重载,友元输出重载
#include using namespace std;class T{public: T():buf(NULL){} T(char *s) { buf = new char[strlen(s) + 1]; strcpy(buf, s); } T(const T& t) { char* t_
2013-09-16 14:01:01
648
原创 KMP
#include using namespace std;void set_next(int* next, char *s){ int k, j; int len = strlen(s); next[0] = -1; for(k=1; k<len; k++) { j = k-1; while(1) {
2013-09-16 11:27:23
545
原创 句子反转,单词不反转
#include using namespace std;void reverse(char* s,int left, int right){ while(left<right) { swap(s[left], s[right]); left++; right--; }}void reverse_sentence
2013-09-15 20:10:35
785
原创 链表 快排
注意指向指针的指针的应用。#include #include using namespace std;struct node{ int data; node* next;};node* partion(node** head, node* end){ // coutdata<<" "; // if(end==NULL) //
2013-09-14 01:41:41
687
原创 1~n,1出现的次数
主要思想,分别考虑每位(个位,十位,不是二进制的位)为1的情况,特别考虑最高位是1和不是1的情况。使用递归,如 f(253)=f(200)+f(50)+f(3)#include #include using namespace std;int f1(int n){ int i, j, k; int num_1=0; for(i=0; i<=n; i++)
2013-09-11 13:00:54
619
原创 链表反转,递归,迭代
#include using namespace std;struct node{ int data; node* next;};node* reverse_link(node* head){ if(head==NULL || head->next==NULL) return head; node* pre; node
2013-09-11 01:39:53
684
原创 最大子数组和
#include using namespace std;void f(){ int a[] = {-6,-8, -5, -9}; int len = sizeof(a)/sizeof(a[0]); int sum = a[0] ; int d = a[0]; int i; for(i=1; i<len; i++) {
2013-09-10 21:35:12
577
原创 最长递增子序列
#include using namespace std;#define N 1000int max_len = 0;int max_right_id = 0;char s[N];int c[N];int pre[N];void print(int id){ if(pre[id] == -1) { cout<<max_len<<": "<<
2013-09-10 21:14:08
556
原创 最长重复子串——后缀数组
#include #include using namespace std;#define N 100char s[N];char suf[N][N];int max_same = 0;int comp(const void *s1, const void* s2){ return strcmp((char*)s1, (char*)s2);}int ge
2013-09-10 20:29:42
536
原创 C++ 继承,虚表内容
#include using namespace std; class D{ public: virtual void d(){cout<<"D::d"<<endl;} // int dd; };class ClassA : public virtual D{public:virtual ~ ClassA(){};virtual void FunctionA(){cout
2013-09-10 13:08:23
577
原创 找出只出现一次的数,其他数都出现了k次
#include using namespace std;int k=3;int find_single(int* a, int n){ int i, j; int single = 0; int temp[32]; for(i=0; i<32; i++) temp[i] = 0; for(i=0; i<n; i
2013-09-08 12:15:15
704
原创 最短路径 Dijkstra
#include #include using namespace std;const int N = 20;const int MAX_DIS = 10000;int dis[N]; //v0到i的最短路径长度int pre[N]; //节点i的前驱int dd[N][N]; //节点之间距离int sort_id[N]; //记录dis[n]排序后的下标,关键int n
2013-09-07 22:23:49
517
原创 字符串排序
后缀数组中,需要排序字符串:#include #include using namespace std;int comp(const void* p1, const void* p2){ return strcmp((char*)p1, (char*)p2);}int main(){ char s[5][6] = {"abc", "abcd", "bcde",
2013-09-07 13:05:38
555
原创 字符串循环移位
#include using namespace std;void reverse_str(char* s, int l, int h){ while(l<h) { swap(s[l++], s[h--]); }}void left_rotate_reverse(char* s, int k, int n){ reverse_str(
2013-09-05 14:47:44
400
原创 编辑距离
距离:插入:1删除:1替换:2,(1也行,改下代码变2为1)#include using namespace std;const int N = 100;int d[N][N];char s1[N], s2[N];inline int three_min(int x, int y, int z){ int a = x<y?x:y; return a<
2013-09-05 13:31:38
463
原创 去重全排列
#include using namespace std;bool is_swap(char* a, int i, int j){ while(i<j) { if(a[i] == a[j]) return false; i++; } return true;}void print_a(char*
2013-09-03 13:30:28
502
原创 1~3000所有包含5,6的数(如56,526,1635)的和
#includeusing namespace std;const int contain_num[] = {5,6};const int num_len = sizeof(contain_num)/sizeof(contain_num[0]);const int MAX = 3000;bool b_has[10] = {false};bool if_contain(int n);
2013-09-02 21:38:02
594
原创 质因数分解
#includeusing namespace std;void func(int n){ int i; for(i=2; i<n; ) { if(n%i == 0) { cout<<i<<"*"; n /= i; } else i
2013-09-02 21:35:00
477
原创 约瑟夫环
72个人,从第9个人开始报数,报到11的人退出,下一位继续从1开始报数,问最后一个人编号。#includeusing namespace std;const int NUM = 72;struct node{ int value; node* next;};void func(){ int i; node* head = new node;
2013-09-02 21:33:55
482
usb_20 usb_20 usb_20 usb_20
2011-06-02
含有zip.lzw.gzip等多种压缩算法的程序
2010-10-28
poi.rar poi excel reader
2010-05-08
播放器程序,由C#实现,可以播放多种形式的电影
2009-12-09
自动售饮料机(包括顾客购买饮料、添加饮料、收银员提取现金)
2009-07-05
学生成绩管理系统(可以按照多种方式对学生成绩进行查询)
2009-07-05
Linux系统分析与高级编程技术
2009-06-12
约瑟夫环(没有用到栈,依然很简单)
2009-04-26
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人