数据结构(浙江大学)(陈越姥姥)
ITNXD
个人博客:https://itnxd.eu.org/
手机号:18834389004 QQ:158903258
展开
-
P1014 Cantor表(模拟 细节)
题的链接:P1014 Cantor表题解: 先找到那条斜线,右上到左下,让 t -= a, 再加 1 即可到达该斜线的第一个部位,再判断当前斜线编号的奇偶性,分情况令 c, d 分别取值,然后一个加一个减即可;注意: 一个小坑点,不是每次都是从右上到左下,还有左下到右上,分为奇偶的情况,细节注意;第一次没看见已提交WA了,改了后就AC了。参考代码1.0:#include <queu...原创 2019-10-15 13:30:55 · 161 阅读 · 0 评论 -
P1022 计算器的改良(细节 字符串)
题的链接:P1022 计算器的改良题解: 这题废了我好长时间才弄懂怎么做,输入还是用getchar即可,输入一个判断一次,若为数字就累计起来,若为加号则加上之前累计的sum,若为负号则减去之前累计的sum,加减之后sum清零,最后就是kx + b = 0这个式子;注意:sum 表示数 ;b 表示系数和 ;now 表示等于号位置(左为1,右为-1);f 表示系数符号;k 表示未知数系...原创 2019-10-14 23:32:25 · 125 阅读 · 0 评论 -
P1464 Function(记忆化搜索)
题的链接:P1464 Function题解: 首先想到直接用dfs按题目要求搜一遍就行,结果一提交全部TLE,发现应该用记忆化搜索:记忆化搜索: 就是在搜索过程中可能同一组值得结果第一次就算出来了,第二次搜索就不要在去搜索这个以前就算出来的值,下一次搜到已经保存的值可以直接使用不用继续去搜索求值!可以大大减少搜索的深度和此数,这样就可以全部AC。百度百科:点击这里!具体解释: 因为是三个变量...原创 2019-10-14 17:08:49 · 227 阅读 · 0 评论 -
03-树3 Tree Traversals Again (25 分)(前中序变后序)
03-树3 Tree Traversals Again (25 分)An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered ...原创 2019-06-26 13:15:16 · 636 阅读 · 0 评论 -
二叉树的前中后序层序遍历的实现(结构体数组存储 递归实现)
二叉树的前中后序遍历(递归实现)#include <iostream>#include <cstdio>#include <string>#include <vector>#include <queue>#include <stack>#include <algorithm>using namesp...原创 2019-07-07 22:58:33 · 384 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树 (25 分)
给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两个正整数N (≤10)和L,分别是每个序列插入元素的个数和需要检查的...原创 2019-07-21 20:46:12 · 438 阅读 · 0 评论 -
堆的初始化,创建,插入,删除以及乱序输入的调整
注意:元素从下标为1开始存储,下标为0,存储最大值,用做哨兵;#include <cstdio>#include <string>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int MAXDATA =...原创 2019-09-23 22:36:01 · 306 阅读 · 0 评论 -
哈夫曼树的创建
带权路径长度(WPL): : 设二叉树有n 个叶子结点 ,每个叶子结点带有权值Wk 为 ,从根结点到每个叶子结点的长度为 Lk ,则每个叶子结点的带权路径长度之和就是: 待定:还没有搞清楚最小堆的结构如何定义//哈夫曼树结构typedef struct HNode{ int Weight; //权值 HNode *Left, *Right;}*HuffmanTr...原创 2019-09-03 21:13:55 · 171 阅读 · 0 评论 -
堆的简单应用(数组实现,打印路径)
#include <cstdio>#include <string>#include <iostream>#include <algorithm>using namespace std;const int maxn = 1001;const int minn = -1;int H[maxn], Size;//堆初始化void...原创 2019-09-03 22:04:06 · 87 阅读 · 0 评论 -
图的邻接矩阵表示法
图的邻接矩阵表示法#include <cstdio>#include <string>#include <iostream>#include <algorithm>#define MaxVertexNum 1010#define INF (1<<31)-1using namespace std;//图的邻接矩阵表示法...原创 2019-09-08 10:04:12 · 464 阅读 · 0 评论 -
图的邻接表表示法
图的邻接表表示法#include <cstdio>#include <string>#include <iostream>#include <algorithm>#define MaxVertexNum 1010#define INF (1<<31)-1using namespace std;//图的邻接矩阵表示法...原创 2019-09-08 12:02:15 · 494 阅读 · 0 评论 -
拯救007(DFS)
This time let us consider the situation in the movie “Live and Let Die” in which James Bond, the world’s most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land ...原创 2019-09-13 13:12:57 · 643 阅读 · 1 评论 -
07-图4 哈利·波特的考试 (25 分)(Floyd算法)
哈利·波特要考试了,他需要你的帮助。这门课学的是用魔咒将一种动物变成另一种动物的本事。例如将猫变成老鼠的魔咒是haha,将老鼠变成鱼的魔咒是hehe等等。反方向变化的魔咒就是简单地将原来的魔咒倒过来念,例如ahah可以将老鼠变成猫。另外,如果想把猫变成鱼,可以通过念一个直接魔咒lalala,也可以将猫变老鼠、老鼠变鱼的魔咒连起来念:hahahehe。现在哈利·波特的手里有一本教材,里面列出了所有...原创 2019-09-14 18:43:25 · 411 阅读 · 0 评论 -
堆排序(堆用数组实现)
堆排序:先将数据用PerDown函数调整为最大堆,然后每次取堆顶最大元素与堆最后一个位置交换,循环一次后将堆以堆顶为根节点继续调整为最大堆(排除最后已经归位的最大元素);注意:堆排序数据从0开始存储;时间复杂度:O(NlogN);#include <queue>#include <cstdio>#include <string>#include &l...原创 2019-09-26 22:55:49 · 1275 阅读 · 0 评论 -
P1706 全排列问题(DFS 全排列)
题目链接:P1706 全排列问题参考代码: 使用dfs深搜一下,避免重复,S[i]保存后将vis设为true,dfs结束取消vis标记;位数够了就输出。#include <cmath>#include <cstdio>#include <string>#include <cstring>#include <iostream>...原创 2019-10-09 13:50:33 · 280 阅读 · 0 评论 -
02-线性结构4 Pop Sequence (25 分)(判断是不是合法出栈顺序)
02-线性结构4 Pop Sequence (25 分)Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a...原创 2019-06-22 23:57:53 · 446 阅读 · 0 评论 -
01-复杂度1 最大子列和问题 (20 分) 算法的持续优化。。。
01-复杂度1 最大子列和问题 (20 分)本题旨在测试各种不同的算法在各种数据情况下的表现。各组测试数据特点如下:数据1:与样例等价,测试基本正确性;数据2:102个随机整数;数据3:103个随机整数;数据4:104个随机整数;数据5:105个随机整数;输入格式:输入第1行给出正整数K (≤100000);第2行给出K个整数,其间以空格分隔。输出格式:在一行中输出最大子列和...原创 2019-06-07 15:03:39 · 356 阅读 · 0 评论 -
01-复杂度3 二分查找 (20 分)
本题要求实现二分查找算法。函数接口定义:Position BinarySearch( List L, ElementType X );其中List结构定义如下:typedef int Position;typedef struct LNode *List;struct LNode { ElementType Data[MAXSIZE]; Position Last; ...原创 2019-06-08 10:11:23 · 167 阅读 · 0 评论 -
01-复杂度2 Maximum Subsequence Sum (25 分)
题目链接:01-复杂度2 Maximum Subsequence Sum (25 分)Given a sequence of K integers { N1 , N2 , …, NK }. A continuous subsequence is defined to be { Ni , Ni+1 , …, Nj } where 1≤...原创 2019-06-08 19:07:20 · 819 阅读 · 0 评论 -
线性表实现
线性表以数组形式实现#include <iostream>#include <cstdio>#include <string>#include <string.h>#include <vector>#include <queue>#include <algorithm>using namespace...原创 2019-06-15 00:04:52 · 814 阅读 · 0 评论 -
栈的实现
手写的Stack:#include <iostream>#include <cstdio>#include <string>#include <vector>#include <queue>#include <list>#include <algorithm>using namespace std;...原创 2019-06-15 13:31:06 · 108 阅读 · 0 评论 -
队列的实现
STL库的queue#include <iostream>#include <cstdio>#include <string>#include <vector>#include <queue>#include <stack>#include <list>#include <algorithm&...原创 2019-06-15 13:48:37 · 93 阅读 · 0 评论 -
02-线性结构1 两个有序链表序列的合并 (15 分)
02-线性结构1 两个有序链表序列的合并 (15 分)本题要求实现一个函数,将两个链表表示的递增整数序列合并为一个非递减的整数序列。函数接口定义:List Merge( List L1, List L2 );其中List结构定义如下:typedef struct Node *PtrToNode;struct Node { ElementType Data; /* 存储结点数据...原创 2019-06-15 15:48:39 · 140 阅读 · 1 评论 -
02-线性结构2 一元多项式的乘法与加法运算 (20 分)
02-线性结构2 一元多项式的乘法与加法运算 (20 分)设计函数分别求两个一元多项式的乘积与和。输入格式:输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。输出格式:输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。零多项式应...原创 2019-06-17 09:40:25 · 1138 阅读 · 0 评论 -
03-树1 树的同构 (25 分)
03-树1 树的同构 (25 分)给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。现给定两棵树,请你判断它们是否是同构的。输入格式:输入给出2棵二叉树树的信息。对于每棵树,首先在一行中给出一个非负整数N (≤10),...原创 2019-06-25 12:26:14 · 157 阅读 · 0 评论 -
03-树2 List Leaves (25 分)(树的层序遍历queue及bfs)
03-树2 List Leaves (25 分)Given a tree, you are supposed to list all the leaves in the order of top down, and left to right.Input Specification:Each input file contains one test case. For each case, ...原创 2019-06-25 13:28:56 · 180 阅读 · 0 评论 -
02-线性结构3 Reversing Linked List (25 分)
02-线性结构3 Reversing Linked List (25 分)Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K=3, the...原创 2019-06-22 00:11:38 · 2502 阅读 · 2 评论 -
1.1-时间记录以及多项式的秦九韶公式
第一个fx是多项式的一般式,第二个是秦九韶公式。。秦九韶公式效率更高,更快。接下来说一下ctime的计时工具:ctime里定义的CLK_TCK,其值每个电脑不一样,我的电脑输出它后显示1000;clock_t start,stop; clock_t这个是数据类型,定义了两个变量用来存储起始时间和终止时间。timee=((double)(stop-start))/CLK_TCK; 终...原创 2019-06-07 11:13:55 · 200 阅读 · 0 评论