12 2020 档案
简单DP + 高精
摘要:洛谷P1255、P2437. 思路相同,注意何时进位以及数组最大长度! #include <stdio.h> short dp[5020][2000] = { 0 }; void f(int n) { dp[0][0] = 0; dp[1][0] = 1; dp[2][0] = 2; int fla 阅读全文
posted @ 2020-12-24 16:13 porest 阅读(111) 评论(0) 推荐(0)
高精度计算
摘要:一. 利用字符串的一维数组方法逐位运算: 高精度加法: 思路很简单,通过数组储存每一位数,然后相加进位。 #include <stdio.h> #include <string.h> int main() { char a[510] = { 0 }, b[510] = { 0 }; int a1[5 阅读全文
posted @ 2020-12-18 23:00 porest 阅读(135) 评论(0) 推荐(0)
树 (tree)
摘要:非空树只有一个根,树的各节点互不相交。 degree == 0, 为 leaf. child, parent, sibling. 各子树不能交换,称之为有序树,否则为无序树。 小结: 根节点:唯一,无双亲。 叶节点:无孩子,可以多个。 中间节点:一个双亲,多个孩子。 双亲表示法: typedef i 阅读全文
posted @ 2020-12-16 09:29 porest 阅读(718) 评论(0) 推荐(0)
串(string)
摘要:串的模式匹配算法: 即字串的定位问题 1.蛮力法:大循环嵌套小循环。 2.KPM模式匹配算法。 阅读全文
posted @ 2020-12-15 19:24 porest 阅读(130) 评论(0) 推荐(0)
队列(queue)
摘要:一端插入一端删除的线性表,FIFO。 循环队列: 为保证队列不出现伪溢出,一般将其构造为循环队列。 为方便判断队列是否已满,将队列满定义为还剩一个数组空间。 队列满的条件:(rear+1)%QueueSize == front (rear队尾, front队头) 队列长度计算公式:(rear-fro 阅读全文
posted @ 2020-12-15 19:14 porest 阅读(414) 评论(0) 推荐(0)
栈(stack)
摘要:栈: Last in First out 线性表,故又称作LIFO结构。 顺序存储:空栈设栈顶指针为-1;否则为数组下标。 #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #pragma warning (disable:499 阅读全文
posted @ 2020-12-15 15:25 porest 阅读(130) 评论(0) 推荐(0)
消消乐的进化之路
摘要:本次作业使用easyX图形库。 version 1.0.1 (an ugly one) 基本实现消消乐的下落,消除的功能。 下个版本需改进的:1. 防止下落过程中消除。 2. 导入游戏初始菜单,尽量实现菜单中的各种功能。 3.显示得分。 #include <stdio.h> #include <gr 阅读全文
posted @ 2020-12-15 14:23 porest 阅读(243) 评论(0) 推荐(0)
线性表
摘要:静态链表: 由数组描述,每个元素由两个数据域组成。 为没有指针的语言设计,但应该尽量理解。 各种链表。 顺序存储结构。 阅读全文
posted @ 2020-12-15 10:05 porest 阅读(62) 评论(0) 推荐(0)
C the basics (linked list)
摘要:相较数组而言,具有更好的空间效率。 单链表的各种操作: 有序单链表的插入一定要考虑清楚多种情况。 #include <stdio.h> #include <stdlib.h> #pragma warning (disable:4996) typedef struct link{ ///build a 阅读全文
posted @ 2020-12-08 19:32 porest 阅读(99) 评论(0) 推荐(0)
C the practice (DMA)
摘要:动态分配复制字符串: #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning (disable:4996) char* strdup(char const* string) { char* new_stri 阅读全文
posted @ 2020-12-08 18:54 porest 阅读(105) 评论(0) 推荐(0)
C the basics (DMA)
摘要:malloc: void *malloc ( size_t size ): 返回指向该内存的指针,若无法获取,则会返回NULL,故使用 malloc 要检查! calloc:void *calloc ( size_t num_elements, size_t element_size ); clea 阅读全文
posted @ 2020-12-08 17:34 porest 阅读(69) 评论(0) 推荐(0)
C the basics (array, complex)
摘要:数组: 只有初始化定义才能 arr = { 0 }; memset(a,0,sizeof(a)); 是中途清零的方法。 结构体: typedef struct namex { }name; 会创建一个name类型的结构体,也可用name进行类型定义,但是不可以定义指针,仍需要用struct name 阅读全文
posted @ 2020-12-08 16:57 porest 阅读(55) 评论(0) 推荐(0)
穷举子集
摘要:Method 1: 采用二进制编码以表示是否出现在集合里。 #include <stdio.h> #include <string.h> #include <math.h> void fun(int num, int bin[]) { ///十进制转化二进制 int i = 0,j; for (j 阅读全文
posted @ 2020-12-08 10:38 porest 阅读(156) 评论(0) 推荐(0)
排序算法(1)
摘要:bubble_sort 比较次数是由数组长度决定,时间会比较长。 void bubble_sort(int arr[], int len) { int i, j, temp; for(i=0; i<len-1; i++) for(j=0; j<len-i-1; j++) if (arr[j] > a 阅读全文
posted @ 2020-12-08 08:56 porest 阅读(79) 评论(0) 推荐(0)