自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 n支队伍比赛,分别编号为0,1,2。。。。n-1,已知它们之间的实力对比关系和出场顺序,求最终排名

#include using namespace std; int w[4][4] = { 0,1,2,3, 1,1,2,3, 2,2,2,3, 3,3,3,3 }; void getResult(int* order,int len,int* result){ int rLen = len; if

2013-04-17 12:22:16 957

原创 求一个矩阵中最大的二维矩阵(元素和最大)

#include using namespace std;int matrix[3][5] = {{1,2,0,3,4},{2,3,4,5,1},{1,1,5,3,0}};int result[2][2];void maxMatrix(int dx,int dy){ int max = 0; int endX = 1; int endY = 1; for(int i = 1 ; i

2013-04-15 15:31:25 506

原创 两个整数序列,其中一个序列表示栈的push顺序, 判断另一个序列有没有可能是对应的pop顺序。

/*此算法为本人猜想,有疑义找到递增的最后一个在这个数后pop不允许出现两个数的顺序都小于它且这两个数的顺序递增如pop序为{1,2,3,6,4,5}先找到6,发现后面44 , 则判定这个pop序为false。又如{1,2,6,5,3,4}先找到6,发现后面33 , 判定为false{1,3,5,2,6,4} 5后面有2,4出现,判定为false*/#include usin

2013-04-13 19:40:03 521

原创 计算二进制中1的位数

#include using namespace std;int countOne(int n){    if(n == 0)        return 0;    int count = 0;    for(int i = 0 ;i         if(n&1 == 1)            count ++;        n = n >> 1;

2013-04-13 16:36:53 403

原创 跳台阶问题

#include using namespace std;int stepJump(int n){ if(n == 1) return 1; if(n == 2) return 2; int t1 = 1; int t2 = 2; for(int i=3;i<=n;i++) { int temp = t2; t2 += t1 ; t1 = temp; } retur

2013-04-13 15:58:25 413

原创 左旋转字符串

#include using namespace std;void leftRotateString(char* s,int len,int c){ c = c % len; for(int i = 0 ; i <= (len -1 )/ 2; i ++) { swap(s[i],s[len - 1 - i ]); } for(i = 0 ; i <= (len - c - 1)

2013-04-12 19:37:38 323

原创 实现continumax函数

#include using namespace std;int continumax(char *out,char *in) {    char* tempHead = NULL;    char* head = NULL;    int tempMax = 0;    int max = 0;    char* cur;    cur = in;

2013-04-12 17:38:06 480

原创 输入两个整数n和m,从数列1,2,3.......n 中随意取几个数, 使其和等于m,要求将其中所有的可能组合列出来。

#include using namespace std;template class Stack{private: class Element{ public: T value; Element(T v){ value = v; next = NULL; } E

2013-04-11 19:16:52 472

原创 o(n)时间寻找第k小的数

//时间复杂度://T(n) = T(n/2) + f(n)//f(n)即为partition(),时间复杂度o(n)//由主定理可知a=1,b=2//log b a < 1//符合主定理第三种情况//因此由o(T(n))=o(f(n)) = o(n)#include using namespace std;int* partition(int* start,int* end){

2013-04-11 18:28:48 582

原创 根据上排给出十个数,在其下排填出对应的十个数 ,要求下排每个数都是先前上排那十个数在下排出现的次数。

例:上排: 0,1,2,3,4,5,6,7,8,9 下排: 6,2,1,0,0,0,1,0,0,0 #include using namespace std;void arrange(int* count,int len){ int* temp = new int[len]; int n = 0; for(int i=0;i<len;i++) { memset(t

2013-04-11 13:15:41 501

原创 判断整数序列是不是二元查找树的后序遍历结果

//实际上就是判断能否由后序和中序序列建树#include using namespace std;class BinTree{public: BinTree(int v){ value = v; left = NULL; right = NULL; } int value; BinTree* left; BinTree* right;};int* getPos

2013-04-10 20:37:19 376

原创 将字符串中的单词翻转

#include using namespace std;//先整体逆置,再逐词逆置void wordReverse(char* s,int len) { char temp; int l = 0; int r = len - 1; while( l < r) { temp = s[l]; s[l] = s[r]; s[r] = temp; l++; r--;

2013-04-10 19:37:40 410

原创 求二叉树中节点的最大距离

#include using namespace std;int count = 0;class BinTree{public: BinTree(int v){ value = v; left = NULL; right = NULL; } int value; BinTree* left; BinTree* right;};int max(int a,int b

2013-04-10 19:02:31 348

转载 求1+2+…+n.要求不能使用乘除法、for、while、if、else、switch、case等关键字

题目:求1+2+…+n,要求不能使用乘除法、for、while、if、else、switch、case等关键字以及条件判断语句(A?B:C)。-----------------循环只是让相同的代码执行n遍而已,我们完全可以不用for和while达到这个效果。比如定义一个类,我们new一含有n个这种类型元素的数组,那么该类的构造函数将确定会被调用n次。我们可以将需要执行的

2013-04-10 18:12:14 725

原创 输出链表的倒数第k个节点

#include using namespace std;class List {public: List(int num) { this->num = num; } int num; List* next;};//创建链表List* createList(int count) { if(count == 0 ) return N

2013-04-10 17:38:32 399

原创 在一个排好序的数组中查找和为sum的两个数

#include using namespace std;int ret[2];bool find(int* num,int len,int sum){    int l = 0;    int r = len - 1;    while(l != r) {        if(num[l] + num[r] == sum){            ret[0] =

2013-04-10 16:28:28 758

原创 查找字符串中第一个出现的不重复的字符

#include using namespace std;int map[256] = {0};char firstUnique(char* s,int len){ for(int i = 0 ; i < len ; i ++) { map[s[i]] ++; } for(i = 0 ; i < len ; i ++) { if(map[s[i]] == 1) retur

2013-04-10 15:47:10 525

原创 约瑟夫环

/*f(n) = (f(n-1) + m ) % n求数学证明!!!!*/#include using namespace std;int lastRemaining(int n,int m){ int l = 0; for(int i=2;i<=n;i++){ l = (l+m)%i; } return l;}int main(){ for(int i=1;i<1

2013-04-10 15:23:33 329

原创 fibonacci数列

// 0 n=0//f(n)= 1 n=1,2// f(n-1)+f(n-2) n>2#include using namespace std;int max(int a, int b) { return a > b ? a : b;}int fibonacci(int n){

2013-04-10 13:51:06 349

原创 最长公共子序列

//状态转移方程://f[i][j] = f[i-1][j-1]+1 if i == 0 || j == 0//f[i][j] = f[i-1][j-1]+1 if str[i] == str[j]//f[i][j] = max(f[i-1][j],f[i][j-1]) if str[i] != str[j]#include using namespace std;int max

2013-04-09 19:53:34 447

原创 0-1背包问题

//状态转移方程:f[i][j] = max(f[i-1][j],f[i-1][j-w[i]]+v[i])//i表示计算范围为前i个物品,j表示剩余的空间#include using namespace std;int max(int a, int b) { return a > b ? a : b;}//分治法int knapsack(int *w,int *v,int len,

2013-04-09 18:48:43 267

原创 连续子数组最大和

#include using namespace std;int maxSum(int *a,int len){ int maxSum = 0; int temp = 0; for(int i = 0 ; i < len ; i ++ ) { if(temp >= 0) temp += a[i]; else temp = a[i]; if(temp >= max

2013-04-09 14:45:30 378

原创 另一种先序遍历和中序遍历的非递归算法

#include using namespace std;//================================栈定义=========================template class Stack{private: class Element{ public: T value; Element(T v){ value = v; next

2013-04-02 16:04:31 480

原创 先序遍历,中序遍历的非递归方法

#include using namespace std;//================================栈定义=========================template class Stack{private:    class Element{    public:        T value;        Element(T

2013-04-02 15:10:10 319

原创 用链表实现栈

#include using namespace std;template class Stack{private: class Element{ public: T value; Element(T v){ value = v; next = NULL; } Element* next; }; Element* top;public: Stack

2013-04-01 19:32:23 425

原创 先序,中序,后序遍历二叉树

#include using namespace std;int count = 0;class BinTree{public: BinTree(int v){ value = v; left = NULL; right = NULL; } int value; BinTree* left; BinTree* right;};void createTree(Bi

2013-04-01 19:03:32 423

原创 判断一个字符串是否对称

#include using namespace std;bool isSym(char* str) { int len = strlen(str); char* p1 = str; char* p2 = str + len - 1; while(p1 < p2) { if(*p1++ != *p2--) return false; } return true;}

2013-04-01 14:51:09 703

原创 删除链表的倒数第n个元素

#include using namespace std;class List {public: List(int num) { this->num = num; } int num; List* next;};//创建链表List* createList(int count) { if(count == 0 ) return

2013-04-01 14:42:31 410

原创 不重复地输出升序数组中的元素

#include using namespace std;void printUnique(int* array,int len) { if(!len) return; if(len == 1) { cout<<array[0]<<endl; } else { int value = array[0]; cout<<value<<endl; for(int i =

2013-04-01 14:15:26 665

原创 在双向链表中删除指定元素

#include using namespace std;class List {public: List(int num) { this->num = num; } int num; List* next; List* pre;};//创建链表List* createList(int count) { if(count ==

2013-04-01 14:03:35 1575

原创 长整形转换为字符串

#include using namespace std;char* ltoa(long l) { char* ret; long t = l; int count = 0; while(t) { t /= 10; count ++; } ret = (char*) malloc(count * (sizeof(char) + 1)); t = l; ret[coun

2013-04-01 13:30:54 1924

空空如也

空空如也

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

TA关注的人

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