上一页 1 2 3 4 5 6 7 8 9 ··· 25 下一页
摘要: ou are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?分析:类似斐波那契序列,使用动态规划的思想。定义f(n)为台阶数为n时青蛙跳到台阶顶部的方法数。那么当n>2 时f(n) = f(n-1) + f(n-2) f(1) = 1; f(2) = 2;class Solution {public: int climbSta 阅读全文
posted @ 2013-09-26 22:23 冰点猎手 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 写本篇主要是为了将基础知识梳理一遍,天天加一些基本东西,以后复习时可以返回来看看。数据结构&&基础算法:基本算法: 二分查找二叉树: 二叉树的各种遍历位操作:排序:排序算法总结图论: 总结RMQ : ST 阅读全文
posted @ 2013-09-26 16:46 冰点猎手 阅读(141) 评论(0) 推荐(0) 编辑
摘要: 1 prim 算法 O(n2) 贪心/* 最小生成树Prim 算法: 贪心思想,随机选择一个点当做最小生成树的初始节点,然后把图的顶点分成A集合(含初始节点), B集合(剩余节点)每次选择A集合中的点到B集合中点的最短距离的边,然后用加入的点去松弛A集合点到B集合点的距离信息。不断迭代, 最终得到最小生成树。*/struct Edge{ int start_, end_; float weight_;};void prim(vector> &map, Edge *&mist){ int n = map.size(); if(n > &grap... 阅读全文
posted @ 2013-09-26 16:45 冰点猎手 阅读(172) 评论(0) 推荐(0) 编辑
摘要: 对于T(n) = a*T(n/b)+c*n^k;T(1) = c 这样的递归关系,有这样的结论:if (a > b^k) T(n) = O(n^(logb(a)));logb(a)b为底a的对数if (a = b^k) T(n) = O(n^k*logn);if (a < b^k) T(n) = O(n^k); 阅读全文
posted @ 2013-09-21 20:19 冰点猎手 阅读(298) 评论(0) 推荐(0) 编辑
摘要: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is in the array. class Solution {public: bool search(int A[], int n, int target) { // Start typing your C/C+. 阅读全文
posted @ 2013-09-21 12:23 冰点猎手 阅读(106) 评论(0) 推荐(0) 编辑
摘要: 1 字符串转换为整数 itao2 strstr3 string的构造函数 、析构函数、 拷贝构造函数、 复制函数4Char ** StrToK(const char* S1,const char* S2)实现该函数,功能:S2将S1字符串截断后,分别输出截断的字符串。举例例如S1=abcdefg, S2=be,将a,cd,fg三个字符串用指向指针的指针返回。 阅读全文
posted @ 2013-09-21 10:50 冰点猎手 阅读(140) 评论(0) 推荐(0) 编辑
摘要: int sum(int a, int b){ int carry = 1; int res = 0 ; while(carry != 0){ res = a^b; carry = (a&b)<<1; a = res; b = carry; } return res;} 阅读全文
posted @ 2013-09-21 10:16 冰点猎手 阅读(131) 评论(0) 推荐(0) 编辑
摘要: class Temp{public: Temp(){ ++N; sum+=N; } static void Reset(){ N = 0; sum = 0; } static int getSum(){ return sum; }private: static int N; static int sum;};int Temp::N = 0;int Temp::sum = 0;int sum(int n){ Temp::reset(); Temp * a = new ... 阅读全文
posted @ 2013-09-21 10:10 冰点猎手 阅读(162) 评论(0) 推荐(0) 编辑
摘要: bool compare(const void * a, const void * b){ return *(int *)a <= *(int *)b;}bool IsContinues(int number[], int length){ if(number == NULL || length <1) return false; qsort(number,length, sizeof(int),compare); int numberofzero =0; int cur = 0; while(cur < length && number[cur] == 0. 阅读全文
posted @ 2013-09-21 09:34 冰点猎手 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 第20题:字符串数组seq[] = a,b,c,d,aa,ba,ca,da,ab,bb,cb,db,ac...,aaa,baa,...(1)aaa是第几个字符串(2)ababacd是第几个(3)第1000个字符串是什么(4)编写函数find(),返回字符串在seq中是第几个(语言不限)分析: 四进制数,右边是高位。已知一个字符串,求第几个:int getindex(char a[]){ int len = strlen(a); if(len 0){ int current = index % 4; char c = getchar(current); ... 阅读全文
posted @ 2013-09-19 17:07 冰点猎手 阅读(199) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 25 下一页