简单的线段树,多余的就不解释了。 1 #include 2 #include 3 4 using namespace std; 5 #define INF 0xffffff0 6 #define max(a,b) (a>b?a:b) 7 #define min(a,b) (a Tree[root]....
分类:
其他好文 时间:
2014-07-27 21:37:10
阅读次数:
216
题意: 树的前,中序遍历求后序遍历。基础题。code#include #include using namespace std;string sq, sh;int len;void make (int l, int r, int t, int w) { if (l > r || t > w) r.....
分类:
其他好文 时间:
2014-07-27 21:34:05
阅读次数:
195
UVA 10410 - Tree Reconstruction
题目链接
题意:给定一个树的dfs序列和bfs序列,求出这颗树
思路:拿dfs的序列,分成若干段,每一段相当一个子树,这样就可以利用bfs的序列去将dfs的序列分段,然后利用一个队列去存放每一段,不断求出子树即可。一开始以为parse tree一定是二叉树,原来不一定啊。
代码:
#include
#i...
分类:
其他好文 时间:
2014-07-27 11:49:23
阅读次数:
155
递归输出就行了
#include
using namespace std;
struct tree{
int dot;
string s;
}t[1020];
int si[1020],a[1020][1020];
void print(int x)
{
for(int i=0;i<=si[x]-1;i++)
{
for(int j=1;j<=t[...
分类:
其他好文 时间:
2014-07-27 11:48:53
阅读次数:
188
10628. Count on a treeProblem code: COTYou are given a tree with N nodes.The tree nodes are numbered from 1 to N.Each node has an integer weight.We wi...
分类:
其他好文 时间:
2014-07-27 10:31:42
阅读次数:
304
Description
Given a connected undirected graph, tell if its minimum spanning tree is unique.
Definition 1 (Spanning Tree): Consider a connected, undirected graph G = (V, E). A spanning tree of...
分类:
其他好文 时间:
2014-07-26 17:19:22
阅读次数:
401
原理就是先利用两个数间的差分,因为把一段连续的数做标记相当于头差分+1,尾差分-1,然后做前缀和即可。可以想到,相比segment tree这种个只适合于查询操作不多但修改操作很多的情况(如果保存前缀和修改又会降速),否则计算前缀和会很费时。/*ID:esxgx1LANG:C++PROG:hdu15...
分类:
其他好文 时间:
2014-07-26 17:05:31
阅读次数:
233
Compared with I version, the tree could be incomplete. The only difference is that, we connect current node's child to next non-childrenless' node's f...
分类:
其他好文 时间:
2014-07-26 17:02:11
阅读次数:
316
Description
Christmas is coming to KCM city. Suby the loyal civilian in KCM city is preparing a big neat Christmas tree. The simple structure of the tree is shown in right picture.
The tree can ...
分类:
其他好文 时间:
2014-07-26 15:01:50
阅读次数:
300
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example: Given binary tree {3...
分类:
其他好文 时间:
2014-07-26 14:03:16
阅读次数:
174