题意:输入众多字符串(中间有空格),按字典序输出,且输出每个字符串所占整个字符串数量的百分比
思路:用字典树的先序遍历,遍历到字符串的末尾便输出并算出百分比即可
这题同样用C++stl map 可以很好解决,但毕竟题目是字典序,比如逆序就字典树同样可以解决
//1632K 782MS
#include
#include
#include
#include
using namespace st...
分类:
编程语言 时间:
2015-02-28 08:55:35
阅读次数:
168
当年老师给我们讲这里的时候,讲的真是云里雾里的。
。其实画个图就很容易理解的事情,为什么扯那么远
我觉得 DFS其实就是树的先序遍历的强化版本
BFS是层序遍历的强化
只不过 图的实现方式比较多元化 而且不像二叉树有明确的根
操作起来相对难一些
理论其实很好理解 就是具体操作起来 每次都很晕的样子
眼高手低了又。
图的遍历是指从图中的任一顶点出发,对图中的所有顶点访...
分类:
其他好文 时间:
2015-02-22 11:06:58
阅读次数:
269
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.这道题要求用先序和中序遍历来建...
分类:
其他好文 时间:
2015-02-20 14:08:33
阅读次数:
169
由先序遍历和中序遍历序列可唯一还原出二叉树,前提条件是所有节点的关键字无重复。题目来源:http://hihocoder.com/problemset/problem/1049代码: 1 #include 2 #include 3 4 using namespace std; 5 6 voi...
分类:
其他好文 时间:
2015-02-18 11:50:18
阅读次数:
162
Given preorder and inorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree.[Solution]先序定根,...
分类:
其他好文 时间:
2015-02-18 11:47:49
阅读次数:
151
求二叉树的先序遍历Time Limit: 1000ms Memory limit: 65536K有疑问?点这里^_^题目描写叙述已知一棵二叉树的中序遍历和后序遍历,求二叉树的先序遍历输入输入数据有多组,第一行是一个整数t (t#include #include struct node{ cha...
分类:
其他好文 时间:
2015-02-17 22:13:40
阅读次数:
207
#include
#include
#include
typedef struct BiTNode{
char e;
struct BiTNode *lchild,*rchild;
}BiTNode;
void preOrderTravse(BiTNode *T1){
if(T1){
printf("%c",T1->e);
preOrde...
分类:
其他好文 时间:
2015-02-17 15:22:11
阅读次数:
223
根据序遍历的特点,我们可以知道,对任意一棵二叉树tree,其后序遍历(ch)的最后一个字符就是这课二叉树的根节点x,然后我们可以在其中序遍历(sh)中把x找出来(假设为第i个字符),显然中序遍历中x前面的字符串(copy(sh,1,i-1))是tree的左子树的中序遍历,x后面的字符串是tree的....
分类:
其他好文 时间:
2015-02-15 14:49:13
阅读次数:
164
题目:如何根据二叉树的先序遍历和中序遍历结果还原二叉树?比如,先序遍历结果是{1,2,4,7,3,5,6,8},中序遍历结果是{4,7,2,1,5,3,8,6};
参考:http://blog.csdn.net/chdjj/article/details/37961347
代码:
#include
#include
#include
struct ...
分类:
其他好文 时间:
2015-02-11 22:01:23
阅读次数:
185
贴出学习C++数据结构线索化二叉树的过程,方便和我一样的新手进行测试和学习同时欢迎各位大神纠正。不同与普通二叉树的地方会用背景色填充//BinTreeNode_Thr.h 1 enum PointTag 2 {Link,Thread}; 3 4 template 5 struct BinTreeN....
分类:
编程语言 时间:
2015-02-11 20:31:13
阅读次数:
229