# UVA 699 The Falling Leaves

不需要真的建树 把当前位置的sum[]加上当前值就行了

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <set>
#define pi acos(-1.0)
#define LL long long
#define ULL unsigned long long
#define inf 0x3f3f3f3f
#define INF 1e18
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define debug(a) printf("---%d---\n", a)
#define mem0(a) memset(a, 0, sizeof(a))
#define memi(a) memset(a, inf, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
using namespace std;
typedef pair<int, int> P;
const double eps = 1e-10;
const int maxn = 1e6 + 5;
const int mod = 1e8;

int sum[maxn];
void Build(int pos)
{
int v;
cin >> v;
if (v == -1) return;
sum[pos] += v;
Build(pos-1);
Build(pos+1);
}
int main(void)
{
//	freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin);
int v, cas = 1, pos;
while (cin >> v){
if (v == -1) break;
memset(sum, 0, sizeof(sum));
pos = maxn / 2;     //树根的水平位置
sum[pos] += v;
Build(pos-1);
Build(pos+1);
while (sum[pos]) pos--;	// 找最左边的结点
printf("Case %d:\n", cas++);
printf("%d", sum[++pos]);
while (sum[++pos])
printf(" %d", sum[pos]);
puts("\n");
}

return 0;
}


#### UVa 699 The Falling Leaves(递归建树)

2014-09-24 12:48:14

#### The Falling Leaves UVA - 699 二叉树 深搜

2017-10-19 13:47:22

#### UVA - 699 The Falling Leaves 二叉树

2016-07-11 14:21:27

#### UVa 699.The Falling Leaves【7月23】

2015-07-23 21:57:58

#### The Falling Leaves UVA - 699

2017-03-25 20:47:17

#### Uva - 699 - The Falling Leaves

2015-06-16 11:01:19

#### uva 699 The Falling Leaves

2013-10-07 23:04:32

#### UVa 699 Falling Leaves

2015-10-09 10:20:04

#### UVa 699 - The Falling Leaves

2014-04-26 10:45:15