摘要: 第一次用了建树的方法,比较繁琐,《数据结构》课程中又介绍了不用建树的思路,根据先序和中序直接得到后序遍历的结果,代码如下: 1 void solve( int preL, int inL, int postL, int n) //当前处理树的三种遍历的第一个元素和树的规模 2 { 3 if(n==0 阅读全文
posted @ 2018-04-04 18:03 又啦 阅读(125) 评论(0) 推荐(0)
摘要: 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 t 阅读全文
posted @ 2018-04-04 17:56 又啦 阅读(124) 评论(0) 推荐(0)
摘要: 给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。 图1 图2 现给定两棵树,请你判断它们是否是同构的。 输入格式: 输入给出2棵 阅读全文
posted @ 2018-04-04 17:54 又啦 阅读(168) 评论(0) 推荐(0)
摘要: Pop Sequence 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 阅读全文
posted @ 2018-03-22 00:04 又啦 阅读(540) 评论(0) 推荐(0)
摘要: Reversing Linked List 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, give 阅读全文
posted @ 2018-03-21 23:46 又啦 阅读(201) 评论(0) 推荐(0)
摘要: 设计函数分别求两个一元多项式的乘积与和。 输入格式: 输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。 输出格式: 输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空 阅读全文
posted @ 2018-03-21 23:26 又啦 阅读(497) 评论(0) 推荐(0)
摘要: 由于选修了《人工智能模式识别》的课程,要求用phthon来实现算法,乘着周三晚上没课,就来回顾一下python的主要语法。 环境: Anaconda Python3.6 1.变量: 在python中,变量是不需要提前声明类型的 1 #data type 2 str_test = "China" 3 阅读全文
posted @ 2018-03-08 13:49 又啦 阅读(641) 评论(0) 推荐(0)