题意:给出按先序输入的一颗二叉树,分别求出从左到右的相同横坐标上的节点的权值之和

递归建树,然后用sum数组分别统计每一个横坐标上的权值之和

感觉建树都在递归递归递归= =慢慢理解吧

 #include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<algorithm>
using namespace std; typedef long long LL;
const int maxn=;
int sum[maxn]; void build(int p){
int v;
cin>>v;
if(v==-) return;
sum[p]+=v;
build(p-);//建左子树
build(p+);//建右子树
} bool init(){
int v;
cin>>v;
if(v==-) return false;
memset(sum,,sizeof(sum));
int pos=maxn/;
sum[pos]=v;
// printf("init被调用\n");
build(pos-);build(pos+);
} int main()
{
int kase=;
while(init()){
int p=;
while(sum[p]==) p++;
cout<<"Case "<<++kase<<":\n"<<sum[p++];
while(sum[p]!=) cout<<" "<<sum[p++];
cout<<"\n\n";
}
return ;
}

go---go--go

UVa 699 The Falling Leaves的更多相关文章

  1. UVA.699 The Falling Leaves (二叉树 思维题)

    UVA.699 The Falling Leaves (二叉树 思维题) 题意分析 理解题意花了好半天,其实就是求建完树后再一条竖线上的所有节点的权值之和,如果按照普通的建树然后在计算的方法,是不方便 ...

  2. UVa 699 The Falling Leaves(递归建树)

    UVa 699 The Falling Leaves(递归建树) 假设一棵二叉树也会落叶  而且叶子只会垂直下落   每个节点保存的值为那个节点上的叶子数   求所有叶子全部下落后   地面从左到右每 ...

  3. UVA 699 The Falling Leaves (二叉树水题)

    本文纯属原创.转载请注明出处,谢谢. http://blog.csdn.net/zip_fan. Description Each year, fall in the North Central re ...

  4. UVa 699 The Falling Leaves (树水题)

    Each year, fall in the North Central region is accompanied by the brilliant colors of the leaves on ...

  5. uva 699 the falling leaves——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA3QAAAMsCAIAAACTL3d2AAAgAElEQVR4nOx9y7GuPA4tKRADk/92T8 ...

  6. uva 699 The Falling Leaves dfs实现

    额,刘汝佳小白里面的配套题目. 题目求二叉树同垂直线上结点值的和. 可以用二叉树做,挺水的其实. 尝试使用dfs实现了:开一个大点的数组,根节点为最中间那点,然后读取时就可以进行和的计算了. 代码: ...

  7. uva 699 The Falling Leaves(建二叉树同一时候求和)

    本来看着挺难的.大概是由于我多瞟了一眼题解,瞬间认为简单多了.做题就得这样,多自己想想.如今是 多校联赛,然而我并不会做. .. .慢慢来,一直在努力. 分析: 题上说了做多不会超过80行.所以能够开 ...

  8. UVA 699 The Falling Leaves (递归先序建立二叉树)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/19244 #include <iostream> #include <cstdio> # ...

  9. UVA - 699The Falling Leaves(递归先序二叉树)

    The Falling Leaves Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Sub ...

随机推荐

  1. foxmail创建163公司企业邮箱的时候会出现ERR Unable to log on

    foxmail创建163公司企业邮箱的时候会出现ERR Unable to log on 解决办法:把pop.qiye.163.com更改为pop.ym.163.com,瞬间创建成功....也许是网易 ...

  2. Flex:在PANEL的title上加一个button[转]

    //转自:http://www.cnblogs.com/GFantasy/archive/2010/03/05/1678917.htmlpackage{ import mx.containers.Pa ...

  3. 合并2个dll成一个,好处你懂的

    步骤一:先下载微软的工具 ilmerge.exe 地址:http://www.microsoft.com/en-us/download/details.aspx?id=17630 步骤二:安装好之后 ...

  4. C# - 设置DLL的属性Embed Interop Type 设为False

    错误: Error msg: A reference was created to embedded interop assembly. because of an indirect referenc ...

  5. 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1]。不能使用除法。

    // test14.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  6. 设置go语言语法高亮

    1. 将$GOROOT/misc/vim/go.vim文件拷贝到-/.vim/syntax/目录下 2. 添加下面代码到~/.vimrc文件中 let mysyntaxfile = "XXX ...

  7. 【好玩的应用】QQ连连看辅助工具

    自己学了这么久的C语言,但没有写出过什么可以用的东西来,总觉得心里不爽.这几天实在是不想干正事,在网上瞎逛逛,结果发现有人写了连连看的外挂.顿时觉得这很有意思啊.于是把代码下载下来,捣鼓了捣鼓.发现还 ...

  8. Winform基础 -- 菜单

    快速创建默认菜单 使用控件 MenuStrip : 点击菜单的右上方小三角:选择 [插入标准项] 即可显现出标准的菜单格式: 如果想添加更多的菜单项,可以在   [请在此处键入] 处输入菜单项的名称 ...

  9. String及其他

    String 以下例开始讲解String public class StringDemo { public static void main(String[] args) { // String s ...

  10. excel公式应用大全

    excel公式应用大全 1.ABS函数 函数名称:ABS 主要功能:求出相应数字的绝对值. 使用格式:ABS(number) 参数说明:number代表需要求绝对值的数值或引用的单元格. 应用举例:如 ...