UVA - 699
2014-11-26 10:51
148 查看
The Falling Leaves |
We assume each node in a binary tree "drops" a number of leaves equal to the integer value stored in that node. We also assume that these leaves drop vertically to the ground (thankfully, there's no wind to blow them around). Finally, we assume that the nodes are positioned horizontally in such a manner that the left and right children of a node are exactly one unit to the left and one unit to the right, respectively, of their parent. Consider the following tree:
#include <iostream> #include <cstdio> #include <cstring> #include <queue> using namespace std; void create(int num,int* a) { int data; cin >> data; if (data == -1) return; a[num] += data; create(num - 1,a); create(num + 1,a); } int main () { int head; int Case = 1; freopen("1.in","r",stdin); while (1) { int ans[200]; memset(ans,0,sizeof(ans)); create(90,ans); int pos = 0; for (int i = 0;i < 200;i++) { if (ans[i] != 0) ans[pos++] = ans[i]; } if (pos == 0) break; printf("Case %d:\n",Case++); for (int i =0 ;i < pos - 1;i++) cout << ans[i] <<" "; cout << ans[pos - 1] << endl<< endl; } }
View Code
相关文章推荐
- UVA 699 二叉树结合数组求求解点的值
- UVa699-The Falling Leaves(下落的叶子)
- uva_699-The Falling Leaves
- UVA 699(二叉树建树与遍历)
- UVa 699 (二叉树) The Falling Leaves
- The Falling Leaves UVA - 699
- uva 699 The Falling Leaves(建二叉树同时求和)
- UVa 699 The Falling Leaves
- UVa 699 下落的树叶
- uva 699 - The Falling Leaves
- UVa 699 - The Falling Leaves
- uva 699
- UVA 699 The Falling Leaves
- UVa 699 The Falling Leaves 树的深度优先搜索
- UVA 6-10 699 - The Falling Leaves
- UVA699
- 下落的树叶(The Falling Leaves, UVa 699)
- uva 699
- UVA 699 下落的树叶 (p159, 二叉树的 DFS)
- uva 699