树
文章平均质量分 60
ACLJW
这个作者很懒,什么都没留下…
展开
-
03-树1 树的同构
03-树1 树的同构(25 分)给定两棵树T1和T2。如果T1可以通过若干次左右孩子互换就变成T2,则我们称两棵树是“同构”的。例如图1给出的两棵树就是同构的,因为我们把其中一棵树的结点A、B、G的左右孩子互换后,就得到另外一棵树。而图2就不是同构的。图1图2现给定两棵树,请你判断它们是否是同构的。输入格式:输入给出2棵二叉树树的信息。对于每棵树,首先在一行中给出一个非负整数N (≤10),即该树...原创 2017-10-25 18:09:57 · 185 阅读 · 0 评论 -
536:Tree Recovery
Tree Recovery#include<bits/stdc++.h>using namespace std;const int maxn = 30;struct node{ char c; struct node* l = NULL; struct node* r = NULL;};char p[maxn],m[maxn];node* bu...原创 2018-08-08 23:52:49 · 104 阅读 · 0 评论 -
806:Spatial Structures
Spatial Structures#include<bits/stdc++.h>using namespace std;const int maxn = 64 + 5;int n,len;int seq[maxn*maxn];char img[maxn][maxn];struct node{ char c = 0; int cnt = 4; ...原创 2018-08-11 23:25:48 · 176 阅读 · 0 评论 -
712:S-Trees
S-Trees#include<bits/stdc++.h>using namespace std;const int maxn = 7;int n,m,t,cnt = 0;char s[2];int a[maxn];char b[maxn];char leaf[int(pow(2,maxn))];char simu(){ int i = 0,j = t...原创 2018-08-09 22:11:05 · 155 阅读 · 0 评论 -
669:The Falling Leaves
The Falling Leaves这道题还是递归,仿照上道题的思路挺容易的,不过看了看书上的代码个人觉得我的代码更简洁,思路更清晰些哈哈。我的思路:开个负下标数组,记录每个位置的权重之和,用 p 记录当前节点位置,那么其左节点位置为 p - 1,右节点位置为 p + 1,依次递归增加相应位置的权重,同时更新最右和最左边位置。#include<bits/stdc++.h>using ...原创 2018-05-31 13:25:43 · 153 阅读 · 0 评论 -
839:Not so Mobile
Not so Mobile 我的思路:可以将天平看做一棵二叉树,二叉树的每个节点要记录其父节点。然后其实就是一个建树的过程,遇到 0 节点就向下延伸,每当一个节点的左右子树确定(其重量也随之确定),就计算其是否平衡,然后一直向上追溯,直到该节点尚未平衡,继续建树,直至整棵树建好,是否平衡也随之确定。version 1(40ms):#include<bits/stdc++.h>usin...原创 2018-05-31 00:29:22 · 129 阅读 · 0 评论 -
548:Tree
Tree首先根据中序遍历和后序遍历递归地构造二叉树(后续遍历的最后一个节点为二叉树的根节点),然后前序遍历。输入有点坑,你说你直接告诉多少个节点多好。。。我想的是先用fets读取整个串,然后用atoi转化为数字,本地运行没问题可是一提交就报错,暂时还没找到原因,大概是因为回车符的问题,参考了别人的输入方法过了,比我的想法要好。#include<bits/stdc++.h>using ...原创 2018-05-29 23:22:48 · 176 阅读 · 0 评论 -
122:Trees on the level
Trees on the level哈哈 这次是一次AC,好开心啊version 1(指针链表版):#include<bits/stdc++.h>using namespace std;const int maxn = 256 + 5;struct node{ int num = -1; struct node* left = NULL; struct n...原创 2018-05-28 23:40:48 · 168 阅读 · 0 评论 -
679:Dropping Balls
Dropping Balls直接模拟似乎很简单,但是会超时。。。每个小球都会落在根结点上,因此前两个小球必然是一个在左子树,一个在右子树。一般地,只需看小球编号的奇偶性,就能知道它是最终在哪棵子树中。对于那些落入根结点左子树的小球来说,只需知道该小球是第几个落在根的左子树里的,就可以知道它下一步往左还是往右了。依此类推,直到小球落到叶子上。version 1(Time Limited):#incl...原创 2018-05-28 18:34:13 · 154 阅读 · 0 评论 -
05-树9 Huffman Codes
05-树9 Huffman Codes(30 分) In 1953, David A. Huffman published his paper “A Method for the Construction of Minimum-Redundancy Codes”, and hence printed his name in the history of computer science. As ...原创 2017-11-12 01:39:22 · 179 阅读 · 0 评论 -
05-树8 File Transfer
05-树8 File Transfer(25 分) 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. Is it possible to sen...原创 2017-11-07 22:30:07 · 162 阅读 · 0 评论 -
05-树7 堆中的路径
05-树7 堆中的路径(25 分) 将一系列给定数字插入一个初始为空的小顶堆H[]。随后对任意给定的下标i,打印从H[i]到根结点的路径。输入格式:每组测试第1行包含2个正整数N和M(≤1000),分别是插入元素的个数、以及需要打印的路径条数。下一行给出区间[-10000, 10000]内的N个要被插入一个初始为空的小顶堆的整数。最后一行给出M个下标。输出格式:对输入中给出的每个...原创 2017-11-04 23:51:33 · 194 阅读 · 0 评论 -
04-树6 Complete Binary Search Tree
04-树6 Complete Binary Search Tree(30 分) 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 with key...原创 2017-11-04 21:39:42 · 243 阅读 · 0 评论 -
04-树5 Root of AVL Tree
04-树5 Root of AVL Tree(25 分)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 time they differ by m...原创 2017-11-03 14:34:41 · 168 阅读 · 0 评论 -
04-树4 是否同一棵二叉搜索树
04-树4 是否同一棵二叉搜索树(25 分) 给定一个插入序列就可以唯一确定一棵二叉搜索树。然而,一棵给定的二叉搜索树却可以由多种不同的插入序列得到。例如分别按照序列{2, 1, 3}和{2, 3, 1}插入初始为空的二叉搜索树,都得到一样的结果。于是对于输入的各种插入序列,你需要判断它们是否能生成一样的二叉搜索树。输入格式:输入包含若干组测试数据。每组数据的第1行给出两个正整数N (≤...原创 2017-11-01 22:58:47 · 194 阅读 · 0 评论 -
03-树3 Tree Traversals Again
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 fr...原创 2017-10-27 19:50:55 · 348 阅读 · 0 评论 -
03-树2 List Leaves
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...原创 2017-10-26 23:31:49 · 279 阅读 · 0 评论 -
1354:Mobile Computing
Mobile Computing枚举二叉树然后计算其宽度即可,每次枚举两个节点构造一个父节点,计算宽度时需要注意的是每棵树的左节点的右边缘可能超过其右子树的左边缘,反之亦然。#include<bits/stdc++.h>using namespace std;const int maxn = 12;int n,s,idx,w[maxn],vis[maxn];doubl...原创 2018-10-26 17:37:09 · 151 阅读 · 0 评论