UVA - 699 The Falling Leaves
来源:互联网 发布:法律家法律数据库 编辑:程序博客网 时间:2024/06/05 03:19
题目大意:给一个二叉树,求在同一条垂线上的数字的和
解题思路:有一个数组,假设中间那个下标为n,则左右两边的的就是n-1和n+1,如果不是-1,则继续以此模式加下去
#include<cstdio>#include<cstring>int left, right;int a[82];void Tree_DFS(int ll, int rr) {int l_n, r_n;scanf("%d", &l_n);if(l_n != -1) {a[ll] = a[ll] + l_n;if(left > ll)left = ll;Tree_DFS(ll-1,ll+1);}scanf("%d", &r_n);if(r_n != -1) {a[rr] = a[rr] + r_n;if(rr > right)right = rr;Tree_DFS(rr-1,rr+1);}}int main() {int num = 1; while(1) {memset(a,0,sizeof(a));scanf("%d", &(a[40]));if(a[40] == -1)break;left = right = 40;Tree_DFS(39,41);printf("Case %d:\n", num++);printf("%d", a[left]);for(int i = left + 1; i <= right; i++) printf(" %d",a[i]);printf("\n\n");}return 0;}
0 0
- uva 699 - The Falling Leaves
- uva 699 The Falling Leaves
- uva 699 - The Falling Leaves
- UVa 699 - The Falling Leaves
- UVA 699 - The Falling Leaves
- UVa 699 - The Falling Leaves
- uva 699 The Falling Leaves
- uva-699 The Falling Leaves
- UVA 699 The Falling Leaves
- uva 699 The Falling Leaves
- UVA 699 - The Falling Leaves
- uva 699 The Falling Leaves
- uva 699 - The Falling Leaves
- UVa 699 - The Falling Leaves
- UVA 699 The Falling Leaves
- UVA - 699 The Falling Leaves
- UVA 699 The Falling Leaves
- UVA - 699 The Falling Leaves
- android 单选按钮 RadioGroup RadioButton
- Callable和Future
- java得到当月天数
- BroadcastReceiver类和实现短信窃听
- 泛型——类型通配符
- UVA - 699 The Falling Leaves
- C++输入函数的用法和区别
- UVA - 10954 Add All
- 百度2015校招机器学习笔试题
- sprintf,你知道多少?
- PHP阅读书籍
- hdu 1231
- 第5周项目1 电阻的串联
- Leetcode-Remove Duplicates from Sorted List