UVa 699 (二叉树) The Falling Leaves
题意:
按先序方式输入一棵二叉树,节点是带权的,左孩子在父节点的左一个单位,右孩子在父节点的右一个单位,从左到右输出相同水平位置节点之和。
分析:
做了好几道二叉树的题,代码应该也很好理解了。这里maxn开始设了200、500都RE,后来索性开了2000,AC了
紫书上面init函数最后应该加一句 return true;
//#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; const int maxn = ;
int sum[maxn]; void build(int p)
{
int v;
scanf("%d", &v);
if(v == -) return;
sum[p] += v;
build(p - );
build(p + );
} bool Init()
{
int v;
scanf("%d", &v);
if(v == -) return false;
memset(sum, , sizeof(sum));
int pos = maxn / ;
sum[pos] = v;
build(pos - );
build(pos + );
return true;
} int main(void)
{
#ifdef LOCAL
freopen("699in.txt", "r", stdin);
#endif int kase = ;
while(Init())
{
int p = ;
while(sum[p] == ) p++;
//if(kase > 1) printf("\n");
printf("Case %d:\n%d", kase++, sum[p++]);
while(sum[p] != ) printf(" %d", sum[p++]);
printf("\n\n");
} return ;
}
代码君
UVa 699 (二叉树) The Falling Leaves的更多相关文章
- 【例题 6-10 UVA - 699】The Falling Leaves
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 递归模拟就好. [代码] #include <bits/stdc++.h> using namespace std; c ...
- UVA.699 The Falling Leaves (二叉树 思维题)
UVA.699 The Falling Leaves (二叉树 思维题) 题意分析 理解题意花了好半天,其实就是求建完树后再一条竖线上的所有节点的权值之和,如果按照普通的建树然后在计算的方法,是不方便 ...
- UVA 699 The Falling Leaves (二叉树水题)
本文纯属原创.转载请注明出处,谢谢. http://blog.csdn.net/zip_fan. Description Each year, fall in the North Central re ...
- UVa 699 The Falling Leaves(递归建树)
UVa 699 The Falling Leaves(递归建树) 假设一棵二叉树也会落叶 而且叶子只会垂直下落 每个节点保存的值为那个节点上的叶子数 求所有叶子全部下落后 地面从左到右每 ...
- UVA - 699The Falling Leaves(递归先序二叉树)
The Falling Leaves Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Sub ...
- UVa 699 The Falling Leaves (树水题)
Each year, fall in the North Central region is accompanied by the brilliant colors of the leaves on ...
- The Falling Leaves(建树方法)
uva 699 紫书P159 Each year, fall in the North Central region is accompanied by the brilliant colors of ...
- UVa699 The Falling Leaves
// UVa699 The Falling Leaves // 题意:给一棵二叉树,每个节点都有一个水平位置:左儿子在它左边1个单位,右儿子在右边1个单位.从左向右输出每个水平位置的所有结点的权值 ...
- 【数据结构】The Falling Leaves(6-10)
[UVA699]The Falling Leaves 算法入门经典第6章例题6-10(P159) 题目大意:有一颗二叉树,求水平位置的和. 试题分析:乱搞就可以过,将树根节点的pos记为0,向左-1, ...
随机推荐
- CF444C DZY Loves Colors
考试完之后打的第一场CF,异常惨烈呀,又只做出了一题了.A题呆滞的看了很久,领悟到了出题者的暗示,应该就是两个点的时候最大吧,不然的话这题肯定特别难敲,YY一发交上去然后就过了.然后就在不停地YY B ...
- zoj Fibonacci Numbers ( java , 简单 ,大数)
题目 //f(1) = 1, f(2) = 1, f(n > 2) = f(n - 1) + f(n - 2) import java.io.*; import java.util.*; imp ...
- JS正则汇总
1.基本定义: \s:用于匹配单个空格符,包括tab键和换行符; \S:用于匹配除单个空格符之外的所有字符; \d:用于匹配从0到9的数字; \w:用于匹配字母,数字或下划线字符; \W:用于匹配所有 ...
- 高质量图形库:pixellib
点这里 pixellib 是高质量 2D 图形库: 高质量抗锯齿,矢量图形绘制 多种图像格式: RGB, BGR, ARGB, ABGR, RGBA, BGRA 8 / 15 / 16 / 24 / ...
- UVA 11361 - Investigating Div-Sum Property 数位DP
An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is d ...
- HDU 4169 树形DP
Wealthy Family Problem Description While studying the history of royal families, you want to know ho ...
- CoreData的简单使用(一)数据库的创建
iOS有多种数据持久化得方式 plist文件(属性列表) preference(偏好设置,NSUserDefaults) NSKeyedArchiver(归档,用的不多) SQLite 3 (需要导入 ...
- Java学习笔记之:Java 内部类
一.介绍 内部类:存在与类中的类就是内部类,一般用于Android开发. 可以把内部类理解成一种继承关系 1.普通内部类 2.局部内部类 3.静态内部类 4.匿名内部类 二.笔记 1.普通内部类 /* ...
- linux 屏幕录像(recordmydesktop)
需求:命令行工具进行屏幕录像ffcast ffmpeg 简单点的是recordmydesktop. 1. 安装: apt-get install gtk-recordmydesktop recordm ...
- Burpsuite如何抓取使用了SSL或TLS传输的Android App流量
一.问题分析 一般来说安卓的APP端测试分为两个部分,一个是对APK包层面的检测,如apk本身是否加壳.源代码本身是否有恶意内嵌广告等的测试,另一个就是通过在本地架设代理服务器来抓取app的包分析是否 ...