摘要: 设计函数分别求两个一元多项式的乘积与和。 输入格式: 输入分2行,每行分别先给出多项式非零项的个数,再以指数递降方式输入一个多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。 输出格式: 输出分2行,分别以指数递降方式输出乘积多项式以及和多项式非零项的系数和指数。数字间以空 阅读全文
posted @ 2019-02-20 21:31 王清河 阅读(259) 评论(0) 推荐(0) 编辑
摘要: 给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。 图1 图2 现给定两棵树,请你判断它们是否是同构的。 输入格式: 输入给出2棵 阅读全文
posted @ 2019-02-20 21:30 王清河 阅读(199) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2019-02-20 21:29 王清河 阅读(772) 评论(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 @ 2019-02-20 21:29 王清河 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。 输入格式: 输入包含若干组 阅读全文
posted @ 2019-02-20 21:28 王清河 阅读(321) 评论(0) 推荐(0) 编辑
摘要: A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties: The left subtree of a node contains only nodes 阅读全文
posted @ 2019-02-20 21:27 王清河 阅读(214) 评论(0) 推荐(0) 编辑
摘要: An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any 阅读全文
posted @ 2019-02-20 21:27 王清河 阅读(269) 评论(0) 推荐(0) 编辑
摘要: 将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。 输入格式: 每组测试第1行包含2个正整数N和M(≤),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行 阅读全文
posted @ 2019-02-20 21:26 王清河 阅读(478) 评论(0) 推荐(0) 编辑
摘要: We have a network of computers and a list of bi-directional connections. Each of these connections allows a file transfer from one computer to another 阅读全文
posted @ 2019-02-20 21:25 王清河 阅读(497) 评论(0) 推荐(0) 编辑
摘要: 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 d 阅读全文
posted @ 2019-02-20 21:24 王清河 阅读(140) 评论(0) 推荐(0) 编辑
摘要: “六度空间”理论又称作“六度分隔(Six Degrees of Separation)”理论。这个理论可以通俗地阐述为:“你和任何一个陌生人之间所间隔的人不会超过六个,也就是说,最多通过五个人你就能够认识任何一个陌生人。”如图1所示。 “六度空间”理论虽然得到广泛的认同,并且正在得到越来越多的应用。 阅读全文
posted @ 2019-02-20 21:23 王清河 阅读(371) 评论(0) 推荐(0) 编辑
摘要: 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 d 阅读全文
posted @ 2019-02-20 21:22 王清河 阅读(164) 评论(0) 推荐(0) 编辑
摘要: According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insert 阅读全文
posted @ 2019-02-20 21:21 王清河 阅读(372) 评论(0) 推荐(0) 编辑
摘要: According to Wikipedia: Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insert 阅读全文
posted @ 2019-02-20 21:21 王清河 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 给定公司N名员工的工龄,要求按工龄增序输出每个工龄段有多少员工。 输入格式: 输入首先给出正整数N(≤),即员工总人数;随后给出N个整数,即每个员工的工龄,范围在[0, 50]。 输出格式: 按工龄的递增顺序输出每个工龄的员工个数,格式为:“工龄:人数”。每项占一行。如果人数为0则不输出该项。 输入 阅读全文
posted @ 2019-02-20 21:20 王清河 阅读(257) 评论(0) 推荐(0) 编辑
摘要: The ranklist of PAT is generated from the status list, which shows the scores of the submissions. This time you are supposed to generate the ranklist 阅读全文
posted @ 2019-02-20 21:19 王清河 阅读(162) 评论(0) 推荐(0) 编辑
摘要: Given any permutation of the numbers {0, 1, 2,..., N−1}, it is easy to sort them in increasing order. But what if Swap(0, *) is the ONLY operation tha 阅读全文
posted @ 2019-02-20 21:18 王清河 阅读(658) 评论(0) 推荐(0) 编辑
摘要: 单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。 输入格式: 输入第一行给出一个正整数 N(≤ 50 000),是已知夫妻/伴侣的对数;随后 N 行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个 ID 号,为 5 位数字(从 00000 到 阅读全文
posted @ 2019-02-20 16:59 王清河 阅读(612) 评论(0) 推荐(0) 编辑
摘要: 当你试图登录某个系统却忘了密码时,系统一般只会允许你尝试有限多次,当超出允许次数时,账号就会被锁死。本题就请你实现这个小功能。 输入格式: 输入在第一行给出一个密码(长度不超过 20 的、不包含空格、Tab、回车的非空字符串)和一个正整数 N(≤ 10),分别是正确的密码和系统允许尝试的次数。随后每 阅读全文
posted @ 2019-02-20 13:49 王清河 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”。例如 123 和 51 就是朋友数,因为 1+2+3 = 5+1 = 6,而 6 就是它们的朋友证号。给定一些整数,要求你统计一下它们中有多少个不同的朋友证号。 输入格式: 输入第一行给出正整数 N。随后一 阅读全文
posted @ 2019-02-20 09:50 王清河 阅读(651) 评论(0) 推荐(0) 编辑