题意:给出n个点,m条边,和边的信息。边有两种颜色,白色和黑色,现要求构造一个生成树,看能否满足白边的数量是斐波那契数。
这道题比赛的时候,小白想到了一种方法:按边颜色排序后,先用白边优先建树,求出最大白边最大个数maxm,再用黑边优先建树,求出白边最小个数minm,看这两个范围内是否存在斐波那契数。
听上去感觉还挺有道理,但是不知道怎么证明正确性,后来想想,生成树构造完之后,再添加任...
分类:
其他好文 时间:
2014-08-04 14:29:07
阅读次数:
229
题目:Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains on....
分类:
编程语言 时间:
2014-08-04 13:57:17
阅读次数:
242
问题:判断二叉树是否为平衡二叉树分析:树上的任意结点的左右子树高度差不超过1,则为平衡二叉树。 搜索递归,记录i结点的左子树高度h1和右子树高度h2,则i结点的高度为max(h1,h2)=1,|h1-h2|>1则不平衡/** * Definition for binary tree * str...
分类:
其他好文 时间:
2014-08-04 13:39:57
阅读次数:
183
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution stil...
分类:
其他好文 时间:
2014-08-04 13:32:57
阅读次数:
184
N个顶点,M条边,每条边可能为黑色或是白色( 0 or 1 ),问有没有可能用为斐波那契数的数目的白色边构成一棵生成树。所以需要删掉图中的环,根据每次删掉的边有一个白色边的上限和下限,判断一下中间有没有斐波那契数就可以了。实现方法是根据颜色排序,先放黑色边得到的是最小数目的白色边构成的生成树,先放白色边得到是最大数目的白色边构成的生成树。
#include
#include
#include
#...
分类:
其他好文 时间:
2014-08-04 11:03:47
阅读次数:
231
题目:Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution ....
分类:
编程语言 时间:
2014-08-04 10:31:57
阅读次数:
239
很自然想起来递归:
代码:
#include
#include
using namespace std;
typedef struct tree1{
int data;
struct tree1 * lchild;
struct tree1 * rchild;
}Tree,* pTree;
void createTree(pTree & p){
int temp ;
scan...
分类:
其他好文 时间:
2014-08-03 23:23:58
阅读次数:
267
题意:给你一棵树,问你树中距离为k的有多少种情况。解题思路:树形dp 维护每个节点(1-K)深度的情况,解题代码: 1 // File Name: 161d.cpp 2 // Author: darkdream 3 // Created Time: 2014年08月03日 星期日 19时20分10秒...
分类:
其他好文 时间:
2014-08-03 20:36:35
阅读次数:
201
package com.iflytek.tree;
import java.util.Random;
/**
* 二叉查找树
* @author fgtian
*
*/
public class BinaryTree {
public static class BinaryTreeNode {
int mValue; // 数值:以int代替,可以扩展成其他的
Binary...
分类:
其他好文 时间:
2014-08-03 18:09:35
阅读次数:
211
在stl中容器分为两大类,序列式容器和关联式容器。序列式容器:array、vector、heap、priority-queue、list、slist、deque、(stack、queue)最后两个是配接器关联式容器:RB-tree、set、map、multiset、multimap、hashtabl...
分类:
其他好文 时间:
2014-08-03 17:50:15
阅读次数:
232