uva 699 The Falling Leaves dfs实现
来源:互联网 发布:宁皓网 知乎 编辑:程序博客网 时间:2024/06/05 22:48
额,刘汝佳小白里面的配套题目。
题目求二叉树同垂直线上结点值的和。
可以用二叉树做,挺水的其实。
尝试使用dfs实现了:开一个大点的数组,根节点为最中间那点,然后读取时就可以进行和的计算了。
代码:
#include <cstdio>#include <cstring>const int maxn = 10000;int n = 500, tmp, num = 1;int cnt[maxn] = {0};bool input(void) {scanf("%d", &tmp);if (tmp != -1) {cnt[n] += tmp;n--;input();n += 2;input();n--;return true;}elsereturn false;}void output(void) {int i;for (i = 0; i <= maxn; i++)if (cnt[i] != 0)break;printf("Case %d:\n%d", num++, cnt[i++]);for (; i <= maxn; i++)if (cnt[i] == 0)break;elseprintf(" %d", cnt[i]);printf("\n\n");memset(cnt, 0, sizeof(cnt));}int main() {while(input())output();return 0;}
- uva 699 The Falling Leaves dfs实现
- UVa 699 The Falling Leaves (DFS遍历二叉树)
- UVA 699 The Falling Leaves(二叉树|DFS)
- 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
- ARM 中断状态和SVC状态的堆栈切换 (异常)
- 分布式Web服务器架构
- Collections(集合操作的工具类)&集合的同步控制&不可变集合的设置
- HDU-1671-Phone List
- spring—容器启动载入bean过程
- uva 699 The Falling Leaves dfs实现
- 逆向iOS SDK -- _UIImageAtPath 的实现(SDK 6.1)
- 分享一个网络图片控件(WebImage for wp8)
- uva 133 The Dole Queue 双向约瑟夫环 模拟实现
- javapoi读写数据 excel
- ruby+python
- poj 1696 Space Ant
- C/C++ 取整函数ceil(),floor()
- HDU-1672-Cuckoo Hashing