摘要: 简要概述: 《C和指针》第三章对数据进行了描述。 其中主要讲解了---变量的三个属性:作用域、链接属性和存储类型。 这三个属性决定了该变量在“什么地方可以使用”以及“该变量的值能够保持多久”。总结作用域:1、文件作用域、代码块作用域、原型作用域和函数作用域 文件作用域:在代码块之外声明的标识... 阅读全文
posted @ 2014-11-02 09:25 挡不住会飞的鸡 阅读(131) 评论(0) 推荐(0) 编辑
摘要: *(ptr++) += 123;等价于:*(ptr) = *(ptr) + 123; ptr++;而不是:*(ptr++) = *(ptr++) + 123;程序员面试宝典p32#include int main(){ unsigned char a = 0xA5; unsigned char b = ~a >> 4 + 1; printf("%d\n",b);}答案是250.1、算术优先级:“~” 大于 “+” 大于 “>>”2、类型转换:对于混合类型的算术表达式,应将其类型变换为最宽的数据类型。在本题中,~a >> 4 + 1 ,常量 阅读全文
posted @ 2014-03-06 10:31 挡不住会飞的鸡 阅读(338) 评论(0) 推荐(0) 编辑
摘要: 首先明确优先级队列的两个表象:插入元素删除最小元素能够实现上述两个操作的数据结构-----优先级队列。我们可以使用数组(有序或无序)、单链表、二叉查找树、堆等数据结构来实现。为什么选择堆来实现呢?主要是从时间复杂度来考虑数组(有序):插入操作 O(n) 删除操作 O(1)数组(无序):插入操作 O(1) 删除操作 O(n)单链表:插入操作 O(1)(往表头插) 删除操作 O(n)二叉查找树: 插入操作 O(logn) 删除操作 O(logn)堆 ---- 同二叉查找树 (但二叉查找树对于删除操作来说,因为总是删除左子树,会造成树的不平衡)综上所述,选择最小堆来实现优先级队列实现代码:设数组A[ 阅读全文
posted @ 2014-01-12 17:51 挡不住会飞的鸡 阅读(154) 评论(0) 推荐(0) 编辑
摘要: // 1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include #include #include #include #include typedef struct node{ int data; struct node* next;}Link;//链表的建立--无头结点int create(Link* &L,int A[],int n){ //尾插法 int i = 0; L = (Link*)malloc(sizeof(Link)); L->data = A[0]; ... 阅读全文
posted @ 2014-01-01 12:01 挡不住会飞的鸡 阅读(149) 评论(0) 推荐(0) 编辑
摘要: // 1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include #include int minValue(int t1,int t2,int t3){ if(t1 pAEnd) { if(pBBegin > pBEnd) return 0; else return pBEnd - pBBegin+1; } if(pBBegin > pBEnd) { if(pABegin > pAEnd) ... 阅读全文
posted @ 2013-12-31 14:05 挡不住会飞的鸡 阅读(170) 评论(0) 推荐(0) 编辑
摘要: // 1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include #include typedef struct pair{ int* C; int* B; int max;}pair;//最大连续子数组的和pair sum(int* A,int n){ int* B = (int*)malloc(sizeof(int)*(n+1)); //标志 int* C = (int*)malloc(sizeof(int)*(n+1)); //C中存放的是每个子问题的最优解 int... 阅读全文
posted @ 2013-12-30 12:19 挡不住会飞的鸡 阅读(151) 评论(0) 推荐(0) 编辑
摘要: // 1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include #include //0-1背包问题//W:物体重量的序列//V:物体的价值//C:背包所能承受的最大重量/*m[i][j]:表示i个物品,背包最大承受重量为C,所能达到的最大价值1、i=0或j=0时,m[i][j] = 0;2、i>0,且第i个物品的重量大于j时,m[i][j] = m[i-1][j]3、i>0,且第i个物品的重量小于等于j时,m[i][j] = max{m[i-1][j],m[i-1][j-wi]+ 阅读全文
posted @ 2013-12-29 13:52 挡不住会飞的鸡 阅读(128) 评论(0) 推荐(0) 编辑
摘要: // 1.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include #include #include #include int dropLength(int *A,int n){ int max=0; int* B = (int*)malloc(sizeof(int)*n); int i = 0,k = 0; B[0] = 1; for(k=1;k= A[k] && B[i] > max) max = B[i]; } B[k] = max+1; ma... 阅读全文
posted @ 2013-12-28 14:34 挡不住会飞的鸡 阅读(307) 评论(0) 推荐(0) 编辑
摘要: 1、最长公共子序列问题是一个组合优化问题,序列X=,序列Y=的公共子序列有很多,要找出最长的那个解。由于X的子序列有2的m次幂这么多,Y的子序列也有2的n次幂这么多,所以传统解法:先求出X和Y的所有子序列,再去找最长的公共子序列,复杂度很高。2、检验能否利用:动态规划法(记表备查)需要满足两个条件:最优子结构子问题重叠最优子结构:最优解的子解也是某一个子问题的最优解设Z=是X和Y的最长公共子序列则有:(1)当xm==yn时,zk=xm=yn,且Zk-1是Xm-1和Yn-1 的最长公共子序列(2)当xm!=yn时,zk!=xm,则Z是Xm-1和Y 的最长公共子序列(3) 当xm!=yn时,zk! 阅读全文
posted @ 2013-12-28 11:53 挡不住会飞的鸡 阅读(187) 评论(0) 推荐(0) 编辑
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 6 void MATRIX_MULTIPLY(int (*a)[3],int (*b)[4]) 7 { 8 int i = 0,j = 0,k=0; 9 int *c[2] = {0};10 c[0] = (int*)malloc(sizeof(int)*4);11 c[1] = (int*)malloc(sizeof(int)*4);12 memset(c[0],0,sizeof(int)*4);13 memset(c[1... 阅读全文
posted @ 2013-12-26 14:13 挡不住会飞的鸡 阅读(129) 评论(0) 推荐(0) 编辑