UVa 10562 Undraw the Trees 看图写树】的更多相关文章

转载请注明: 仰望高端玩家的小清新 http://www.cnblogs.com/luruiyuan/ 题目大意: 题目传送门:UVa 10562Undraw the Trees 给定字符拼成的树,将这些树转换成特定的括号表示的树 思路: 首先,观察样例,可以发现就是先序遍历的顺序,因此可以确定dfs 但是,还有几个地方需要考虑: 同一级的结点,在同一级的括号中 由于顺序满足先序遍历,因此不需要存储树的括号表示法,更不需要构建树,直接在遍历过程中输出即可. 空树:即输入为:# 时的树的处理,我不…
题目描述: 原题: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://uva.onlinejudge.org/external/105/10562.pdf 紫书P170 直接在二维数组上做DFS,用的fgets函数读入数据,比较gets函数安全,但是会读入 \n,在 DFS 的时候,下一个状态要 不等于空格,并且不等于 \n; #include <bits/stdc++.h> using namespace std; +; char buf[Maxn][Maxn]; int n; void dfs(int r,int c) { prin…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1503 这道题错了好多次,一开始我直接是cin>>t,但前面可能还有空格,所以不对.就按照书上的用了fgets(buf[0],maxn,stdin). 题目的本质就是二叉树的遍历问题,直接运用dfs遍历即可. #include<iostream> #include&l…
题目链接: 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…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABB4AAAM9CAYAAAA7ObAlAAAgAElEQVR4nOyd25GsupKGywVswAV8wARswAU8wAM8IOZ9sAAHeJ4IPMCHnIcdPysrK3UDUUVV5xfRcc5eTUNKypsSSTzIMAzDMAzDMAzDMAzjIh6fFsAwDMMwDMMwDMMwjN/FCg+GYRiGYRiGYRiGYVyGFR4MwzAMwzAMwzAMw7gMKzwYhmEYhmEYh…
题意: 将树的关系用字符串的形式给出 分析: 直接dfs搜索,第i行第j个如果是字母,判断i+1行j个是不是'|'是的话在第i+2行找第一个'-',找到后在第i+3行找字母,重复进行. 代码: #include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int maxn=210;int n;char a[maxn][ma…
题意:将多叉树转化为括号表示法. 分析:gets读取,dfs就好了.注意,样例中一行的最后一个字母后是没有空格的. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib> #include<cctype> #include<cmath> #include<iost…
这个题过的好艰难,不过真的学到好多. 关于fgets的用法真的是精髓.!isspace(c)和c!=' '是有区别的. 其它的看代码吧 #include <iostream> #include <cstring> #include <string> #include <map> #include <set> #include <algorithm> #include <fstream> #include <cstdi…
非常好的dfs题  有很多细节 关于‘ ’  ‘0’  ’\n‘  的处理  他们都属于isspace函数 其中 while(buf[x+2][i]=='-'&&buf[x+3][i]!='\0')  很重要    &&后面去掉的话会自动以\0为目标进行dfs  得到答案不止一行!!! 判断不是空格用!isspace() fgets用于读取行 在string不合适的时候  并且同样会读取换行符 if(n){ for(int i=0;i<strlen(buf[0]);i…