额,刘汝佳小白里面的配套题目。
题目求二叉树同垂直线上结点值的和。
可以用二叉树做,挺水的其实。
尝试使用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;
}
else
return 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;
else
printf(" %d", cnt[i]);
printf("\n\n");
memset(cnt, 0, sizeof(cnt));
}
int main() {
while(input())
output();
return 0;
}
分享到:
相关推荐
自己使用jq html 编写的《falling_bird 坠落的小鸟》 ,自己原创估计有,逻辑上的bug,给大家一个举一反三的示例,谢谢大家,我的邮箱 lizhilimaster@163.com #### 使用方法:按压空格即可(也可以重新开始) github...
外研版一起小学英语六下《Module 4Unit 2 The apples are falling down the stairs.》word教案 (2).docx
ActiveX METEOR Arcade Game. Defend the Earth from falling Meteors. Fast transparent sprite animation and fast collision detection using the (COLLIDE.BAS) collision detection module/engine.
赶在平安夜之际,终于把 Falling Snow On your Desktop 完善的较为满意了。现在的软件不但有比较丰富的雪花图案,而且还配上了一首圣诞歌曲。在打开软件后,会再桌面上一个字一个字出现Merry Christmas 的艺术字祝福...
FLUENT-MDM-tut-01_2d-falling-box
落叶 创建落叶的 SVG 动画的 Python 脚本。
烟雾特效,可以做房屋倒塌的效果,里面由现成的案例作为参考,这个完全是一个特效,当然自己可以调整其效果,最重要的是做VR项目的话,我觉得还是可以的,完全做成那种效果
Like beauty, color is ...asked whether a tree falling in the forest makes a sound if no one is there to observe it. Perhaps equal philosophical energy should be spent wondering what color its leaves are.
falling for ya meme.zipscratch2.0 3.0编程项目源文件源码经典游戏案例素材源代码falling for ya meme.zipscratch2.0 3.0编程项目源文件源码经典游戏案例素材源代码falling for ya meme.zipscratch2.0 3.0编程项目...
原始Falling Sand游戏的python模仿 该项目仍处于ALPHA阶段,正在进行中。 您可以查看“实验”分支,以使用半实现或越野车功能。 实现的功能: 4种元素类型:金属,水,沙子和酸,每种元素都有自己的物理性质 基本...
html实现流星效果
the CK (falling edges of the CK), Data, Data strobes and Write data masks inputs are sampled on both rising and falling edges of it. The data paths are internally pipelined and 8-bit prefetched to ...
The Hynix 16Mx16 DDR SDRAMs offer fully synchronous operations referenced to both rising and falling edges of the clock. While all addresses and control inputs are latched on the rising edges of the ...
HTML实现流星特效
html5-canvas-fire-falling.zip
游戏说明 * Collect the falling stars to gain points* Avoid the fireballs at all costs -- running into one ends the game!* Use the left and right arrows to move from side to side* Use the up arrow to ...
While all addresses and control inputs are latched on the rising edges of the CK (falling edges of the /CK), Data, Data strobes and Write data masks inputs are sampled on both rising and falling ...
While all addresses and control inputs are latched on the rising edges of the CK (falling edges of the CK), Data, Data strobes and Write data masks inputs are sampled on both rising and falling edges...
Falling Enemies2_C#_unity3d_源码