uva536 Tree Recovery
来源:互联网 发布:java链表的实现 编辑:程序博客网 时间:2024/06/06 01:07
重建树。
#include<bits/stdc++.h>using namespace std;int l[30],r[30],pre[30],in[30],n,flag[30],ok;int bulid(int l1,int r1,int l2,int r2){ if(l2>r2) return 0; int t=pre[l1]; int p=l2; while(t!=in[p]) p++; int cnt=p-l2; l[t]=bulid(l1+1,l1+cnt,l2,p-1); r[t]=bulid(l1+cnt+1,r1,p+1,r2); return t;}void post_order(int t){ if(l[t]!=0) post_order(l[t]); if(r[t]!=0) post_order(r[t]); printf("%c",'A'+t-1);}int main(){ string a,b; while(cin>>a>>b){ memset(flag,0,sizeof(flag)); memset(l,0,sizeof(l)); memset(r,0,sizeof(r)); n=a.size(); for(int i=0;i<n;i++) pre[i]=a[i]-'A'+1; for(int i=0;i<n;i++) in[i]=b[i]-'A'+1; bulid(0,n-1,0,n-1); post_order(pre[0]); cout<<endl; }}
0 0
- uva536 Tree Recovery
- uva536 Tree Recovery
- UVA536 - Tree Recovery
- UVa536 Tree Recovery
- uva536 Tree Recovery
- UVA536 Tree Recovery
- uva536 -- Tree Recovery
- Tree Recovery UVA536
- UVA536 - Tree Recovery(递归)
- Uva536——Tree Recovery
- 二叉树重建(Tree Recovery ,UVa536)
- uva536-Tree Recovery-二叉树遍历
- 习题6-3 UVa536 Tree Recovery(树的遍历转换)
- Uva536 Tree Recovery 【递归建树】【习题6-3】
- [UVA548]Tree[根据中序后序构建树][UVA536]Tree Recovery[根据前序中序构建树]
- 算法竞赛入门经典 第二版 习题6-3 二叉树重建 Tree Recovery uva536
- uva536
- uva536
- hibernate @Entity @Table 实体类中不可以随便添加与表字段不对应的get方法,如增加请加注解 @Transient
- Ddr2,ddr3,ddr4内存条的读写速率
- Java 单例模式
- 【UI】【View】自定义布局方法与注意事项(一)
- C++中const用法总结
- uva536 Tree Recovery
- 单片机准双向口IO详解
- cocoapods 安装
- AMD规范
- 公共函数库的介绍与使用
- Animation动画详解(八)——PropertyValuesHolder与Keyframe
- .NET 4 协变和逆变理解
- HTML5 postMessage解决跨域、跨iframe窗口消息传递
- 关联其它表进行update数据