【数据结构】The Falling Leaves(6-10)
[UVA699]The Falling Leaves
算法入门经典第6章例题6-10(P159)
题目大意:有一颗二叉树,求水平位置的和。
试题分析:乱搞就可以过,将树根节点的pos记为0,向左-1,向右+1,统计答案即可。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std; inline int read(){
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
const int MAXN=1000;
const int INF=999999;
int N,M;
int sum[MAXN];
int Min,Max;
int cnt; void solve(int pos){
int ls=read();
Max=max(Max,pos);
Min=min(Min,pos);
if(ls!=-1){
sum[pos-1+200]+=ls;
solve(pos-1);
}
int rs=read();
if(rs!=-1){
sum[pos+1+200]+=rs;
solve(pos+1);
}
return ;
}
int k;
int main(){
while(scanf("%d",&k)!=EOF){
if(k==-1) break;
memset(sum,0,sizeof(sum));
Min=Max=0;
sum[200]+=k;
solve(0);
printf("Case %d:\n",++cnt);
for(int i=Min;i<Max;i++){
printf("%d ",sum[i+200]);
}
printf("%d\n\n",sum[Max+200]);
}
}
【数据结构】The Falling Leaves(6-10)的更多相关文章
- UVA 699 The Falling Leaves (二叉树水题)
本文纯属原创.转载请注明出处,谢谢. http://blog.csdn.net/zip_fan. Description Each year, fall in the North Central re ...
- H - The Falling Leaves
Description Each year, fall in the North Central region is accompanied by the brilliant colors of th ...
- UVa699 The Falling Leaves
// UVa699 The Falling Leaves // 题意:给一棵二叉树,每个节点都有一个水平位置:左儿子在它左边1个单位,右儿子在右边1个单位.从左向右输出每个水平位置的所有结点的权值 ...
- UVA - 699The Falling Leaves(递归先序二叉树)
The Falling Leaves Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Sub ...
- POJ 1577 Falling Leaves 二叉搜索树
HDU 3791 Falling Leaves 二叉搜索树 Figure 1Figure 1 shows a graphical representation of a binary tree of ...
- UVA.699 The Falling Leaves (二叉树 思维题)
UVA.699 The Falling Leaves (二叉树 思维题) 题意分析 理解题意花了好半天,其实就是求建完树后再一条竖线上的所有节点的权值之和,如果按照普通的建树然后在计算的方法,是不方便 ...
- The Falling Leaves(建树方法)
uva 699 紫书P159 Each year, fall in the North Central region is accompanied by the brilliant colors of ...
- HDU 3791 二叉搜索树 (数据结构与算法实验题 10.2 小明) BST
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3791 中文题不说题意. 建立完二叉搜索树后进行前序遍历或者后序遍历判断是否一样就可以了. 跟这次的作业第 ...
- UVa 699 The Falling Leaves(递归建树)
UVa 699 The Falling Leaves(递归建树) 假设一棵二叉树也会落叶 而且叶子只会垂直下落 每个节点保存的值为那个节点上的叶子数 求所有叶子全部下落后 地面从左到右每 ...
随机推荐
- HDU 1548 A strange lift (广搜)
题目链接 Problem Description There is a strange lift.The lift can stop can at every floor as you want, a ...
- Spark-2.3.2【SparkStreaming+SparkSQL-实时仪表盘应用】
应用场景:实时仪表盘(即大屏),每个集团下有多个mall,每个mall下包含多家shop,需实时计算集团下各mall及其shop的实时销售分析(区域.业态.店铺TOP.总销售额等指标)并提供可视化展现 ...
- ms17010利用失败解决一则
没有反弹得到session并且提示如下: [-] 10.0.131.2:445 - Service failed to start, ERROR_CODE: 216 换了一个payload set p ...
- 一个简单爬免费代理IP的脚本
- 源码分析之tinyhttpd-0.1
1. 简介: tinyhttpd是使用c语言开发的超轻量级http服务器,通过代码流程可以了解http服务器的基本处理流程, 并且涉及了网络套接字,线程,父子进程,管道等等知识点: 项目地址:http ...
- 【bzoj3223】文艺平衡树
#include<bits/stdc++.h> #define N 300005 #define rat 4 using namespace std; struct Node{ int s ...
- 怎么快速入门一个老的java项目
作者:eilen著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 1.有文档肯定先看文档,先看设计文档,产品的.技术的设计文档,接口文档写的好的可以看看,要是写的不好不着急看. 2 ...
- FineReport——JS二次开发(复选框全选)
在进行查询结果选择的时候,我们经常会用到复选框控件,对于如何实现复选框全选,基本思路: 在复选框中的初始化事件中把控件加入到一个全局数组里,然后在全选复选框里对数组里的控件进行遍历赋值. 首先,定义两 ...
- 调用手机端硬件功能 汇总(android/ios) Native.js示例汇总
Native.js示例汇总 NJS Native.JS 示例 Native.js虽然强大和开放,但很多web开发者因为不熟悉原生API而难以独立完成.这篇帖子的目的就是汇总各种写好的NJS代码,方便w ...
- JQuery一个对象绑定多个事件
jQuery("#id").click(func1).mouseover(func2)//方法连写,func为方法的名字 jQuery("#id").click ...