UVA10562-Undraw the Trees(递归)】的更多相关文章

  注意点: 空树情况处理. >= && buf[r+][i-]=='-') i--; #include<cstdio> #include<cstring> #include<iostream> #include<string> #include<algorithm> using namespace std; +; char buf[N][N]; int n; //递归遍历并且输出以字符buf[r][c]为根的树 void…
传送门: 1. UVA - 10562 2. Vjudge [看图写树]     将题目中给出的树改写为 括号表示法 即 (ROOT (SON1(...) (SON2(...)...(SONn(...))的表示方法,空树括号留空,例如: A | -------- B C D | | ----- - E F G # e | ---- f g # 上图有两棵树,'#'指该棵树如入完毕,将要表示为: (A(B()C(E()F())D(G()))) (e(f()g())) 分析:递归求解的经典题,类似于…
上来一看感觉难以下手,仔细想想就是dfs啊!!!! #include <cstdio> #include<iostream> #include<iomanip> #include<cstring> #include<string> #include<queue> #include<algorithm> using namespace std; ; ][]; void dfs (int x,int y) {//x为第几行,y…
题目描述: 原题: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,…
题目链接: https://cn.vjudge.net/problem/UVA-10562 Professor Homer has been reported missing. We suspect that his recent research works might have had something to with this. But we really don't know much about what he was working on! The detectives tried…
题意:给你画了一颗树,你要把它的前序输出. 题解:读进到二维数组.边解析边输出. 坑:少打了个-1. #define _CRT_SECURE_NO_WARNINGS #include<cstring> #include<cctype> #include<cmath> #include<cstdio> #include<string> #include<stack> #include<list> #include<se…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABB4AAAM9CAYAAAA7ObAlAAAgAElEQVR4nOyd25GsupKGywVswAV8wARswAU8wAM8IOZ9sAAHeJ4IPMCHnIcdPysrK3UDUUVV5xfRcc5eTUNKypsSSTzIMAzDMAzDMAzDMAzjIh6fFsAwDMMwDMMwDMMwjN/FCg+GYRiGYRiGYRiGYVyGFR4MwzAMwzAMwzAMw7gMKzwYhmEYhmEYh…
题意: 给出一个二维字符数组,它代表了一棵树.然后将这棵树转化为括号表示法(以递归的形式). 分析: 这道题最大的特色就是对数据的处理方式,里面用到了一个 fgets() 函数,这个函数的功能有点像c++里面的cin.getline() 函数介绍: 从文件结构体指针stream中读取数据,每次读取一行.读取的数据保存在buf指向的字符数组中,每次最多读取bufsize-1个字符(第bufsize个字符赋'\0'),如果文件中的该行,不足bufsize个字符,则读完该行就结束.如若该行(包括最后一…
转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将这些树转换成特定的括号表示的树 思路: 首先,观察样例,可以发现就是先序遍历的顺序,因此可以确定dfs 但是,还有几个地方需要考虑: 同一级的结点,在同一级的括号中 由于顺序满足先序遍历,因此不需要存储树的括号表示法,更不需要构建树,直接在遍历过程中输出即可. 空树:即输入为:# 时的树的处理,我不…
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟+递归 [代码] #include <bits/stdc++.h> using namespace std; const int N = 200; string s[N+10]; int n; bool is(char key){ if (key!='-' && key != '|' && key != ' ' && key != '#') return true; retu…