S-Trees UVA - 712】的更多相关文章

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=653 题意:给出满二叉树的叶子节点的值,给出路径并输出叶子节点的值 因为是满二叉树,所以就运用满二叉树的性质,往左走时L=2*L,往右走时就是L=2*L+1.这道题里第二行输入的东西完全没用,所以可以直接用个字符串来吃掉它.另外要注意的就是得把输出值先保存下来,最后一起输出. #includ…
二叉树? 怒水~~ 注意一下查询与x值的对应关系就好~ #include <iostream> #include <cstring> #include <cstdio> using namespace std; int main (){ ]; ],b[]; int n; int m; ; while (~scanf ("%d",&n)&&n){ ]; ;i<n;i++){ scanf ("%s",c)…
题意:将多叉树转化为括号表示法,每个非叶结点的正下方都有一个'|'然后下方是一排'-'和字符,恰好覆盖所有子结点的正上方,单独的一行'#'为数据的结束标志 解题思路:用gets将字符数组输入,本题不用建树,直接用广度优先递归求解,同时注意对空树的处理(需要单独判断),以及结点的符号不一定是字母,也可以是其他的符号(用isspace()判断是不是空格,并且单独判断是不是换行符'\0') 笔记:gets是从标准的输入接收一行字符,遇到'\n'时结束,但不接收'\n',把 '\n'留存输入缓冲区:把接…
这个题根本不用建树,因为是完全二叉树,可以把这个想成二进制.对于根是二进制数的首位,之后依次类推.到最后的叶子节点就是从0到pow(2,n)-1. 关键在于在第一次输入的不是按照x1,x2,x3,x4这样的顺序输入的,那么我们就默认他的输入时按从二进制高位到地位.对于查询是按x1,x2,x3,x4这样的顺序.所以不能直接对应,需要一些小的操作来让查询的输入和二进制对的上. #include <iostream> #include <cstring> #include <str…
题意:给你画了一颗树,你要把它的前序输出. 题解:读进到二维数组.边解析边输出. 坑:少打了个-1. #define _CRT_SECURE_NO_WARNINGS #include<cstring> #include<cctype> #include<cmath> #include<cstdio> #include<string> #include<stack> #include<list> #include<se…
题目描述: 原题:https://vjudge.net/problem/UVA-10562 题目思路: 递归找结点 //自己的代码测试过了,一直WA,贴上紫书的代码 AC代码 #include<cstdio> #include<cctype> #include<cstring> using namespace std; + ; int n; char buf[maxn][maxn]; // 递归遍历并且输出以字符buf[r][c]为根的树 void dfs(int r,…
题意: 给定一颗n层的二叉树的叶子, 然后给定每层走的方向, 0代表左边, 1代表右边, 求到达的是那一个叶子. 每层有一个编号, 然后n层的编号是打乱的, 但是给的顺序是从1到n. 分析: 先用一个f数组把一开始打乱的顺序存起来,  将他变为有序, 然后之后读取走的方法, 把他先转化为给定的层次顺序, 然后再转换为给定的二进制序号, 然后转化为十进制就是知道是几个叶子了. #include <bits/stdc++.h> using namespace std; int n, m; ], f…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] dfs模拟一下就好. 先预处理一个dfs. 搞出来x叶子节点它的值是什么 [代码] /* 1.Shoud it use long long ? 2.Have you ever test several sample(at least therr) yourself? 3.Can you promise that the solution is right? At least,the main ideal 4.use the pu…
题意:0往左走,1往右走,已知所有叶子的值,每个查询都是根结点到叶子结点的路径,路径的每一个点分别对应着x1,x2,x3……但是实际上的S树的路径可能并非是x1,x2,x3…… 分析:先存路径变量的顺序,来控制最后访问的顺序. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib> #incl…
  A Strange Tree (S-tree) over the variable set Xn = {x1,x2,...,xn} is a binary tree representing a Boolean function f : {0,1}n → {0,1}. Each path of the S-tree begins at the root node and consists of n + 1 nodes. Each of the S-tree's nodes has a dep…