UVA 699 - The Falling Leaves

原创 2013年12月02日 07:39:12
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
int a[210][210];
int sum[210];
void creat(int dep, int mid)
{
    int x;
    scanf("%d", &x);
    if(x == -1) return;
    else {
        a[dep][mid] += x;
        sum[mid] += x;
        creat(dep+1, mid-1);
        creat(dep+1, mid+1);
    }
}
int main()
{
    int root, kase = 0;
    while(scanf("%d", &root), root != -1)
    {
        memset(sum, 0, sizeof(sum));
        memset(a, 0, sizeof(a));
        int mid = 100;
        a[0][mid] = root;
        sum[mid] += root;
        creat(1, mid-1);
        creat(1, mid+1);
        printf("Case %d:\n", ++kase);
        bool f = true;
        for(int i = 0; i < 200; ++i)
        {
            if(sum[i] != 0)
            {
                if(!f) printf(" "), printf("%d", sum[i]);
                else printf("%d", sum[i]), f = false;
            }
        }
        printf("\n\n");
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

UVa 699 The Falling Leaves (DFS遍历二叉树)

699 - The Falling Leaves Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=co...

UVa 699 - The Falling Leaves

实质上是一个二叉树的DFS,先左子树,再右子树,因为题目说最大宽度为80,所以开一个80的数组,从中间(40)开始,往里递归。 以第二组数据为例, 8 2 9 -1 -1 6 5 -1 -1 ...

uva 699 The Falling Leaves (二叉树)

uva 699 The Falling Leaves Each year, fall in the North Central region is accompanied by the ...

uva 699 - The Falling Leaves

The Falling Leaves  Each year, fall in the North Central region is accompanied by the bri...

UVA - 699 The Falling Leaves

The Falling Leaves  Each year, fall in the North Central region is accompanied by the bri...

UVa 699 The Falling Leaves(递归建树)

题意  假设一棵二叉树也会落叶  而且叶子只会垂直下落   每个节点保存的值为那个节点上的叶子数   求所有叶子全部下落后   地面从左到右每堆有多少片叶子 和上一题有点像  都是递归输入的  一个...
  • acvay
  • acvay
  • 2014-09-24 12:48
  • 957

uva 699 The Falling Leaves

uva 699 The Falling Leaves

The Falling Leaves UVA699

这道题题意很好理解,在判定二叉树的节点数是不是结束的时候我用到了一个定理,二叉树也节点数也就是题中-1的个数等于度数为一和二的结点个数加一,题中不存在度数为一的结点,因此很好判断树的结点是否结束,然后...

UVA 699 The Falling Leaves(二叉树)

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

uva 699 - The Falling Leaves

// uva 699 - The Falling Leaves // 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)