POJ2255 Tree Recovery 前序 中序求后序
来源:互联网 发布:windows配置失败怎么办 编辑:程序博客网 时间:2024/05/20 07:15
根据前序找到在中序的位置 其两端则是其左右节点
#include <stdio.h>#include <string.h>#include <stdlib.h>#include <limits.h>#include <malloc.h>#include <ctype.h>#include <math.h>#include <string>#include <iostream>#include <algorithm>using namespace std;#define MAXN 11111#include <queue>#include <vector>const int INF = 999999;int len1,len2,len;char qian[44],zhong[44],sum[44];void dfs(int s1,int e1,int s2,int e2){ if(s1>=e1) return ; sum[--len]=qian[s1]; int i; for( i=s2;i<e2;i++) if(qian[s1]==zhong[i]) break; dfs(s1+i-s2+1,e1,i+1,e2);//右子树 dfs(s1+1,s1+i-s2+1,s2,i);//左子树}int main(){ // freopen("in.txt","r",stdin); while(scanf("%s %s",qian,zhong)!=EOF) { len1=strlen(qian); len2=strlen(zhong); len=len1; sum[len]=0; dfs(0,len1,0,len2); printf("%s\n",sum); } return 0;}
0 0
- POJ2255 Tree Recovery 前序 中序求后序
- POJ2255 Tree Recovery (先序中序-》后序)
- POJ2255 Tree Recovery
- poj2255 Tree Recovery
- poj2255 Tree Recovery
- POJ2255-Tree Recovery
- poj2255 Tree Recovery(递归)
- POJ2255----Tree Recovery
- POJ2255,Tree Recovery,二叉树重建
- poj2255 Tree Recovery 二叉树遍历
- poj2255~~Tree Recovery (树的遍历构造~)
- poj2255- Tree Recovery(二叉树)
- POJ2255 Tree Recovery 【树的遍历】
- POJ2255 Tree Recovery 二叉树遍历
- POJ2255 Tree Recovery(二叉树遍历)
- poj2255 Tree Recovery(先序+中序→后序)
- POJ2255-Tree Recovery 已知先序遍历和中序遍历求后序遍历
- 【POJ2255】Tree Recovery解题报告 思路 + 数据 +代码
- TextView很窄时,强制将text设置为垂直居中 在onLayout方法中调用此方法
- 黑马程序员__html基础1
- 1024. Palindromic Number (25)
- NSCoding归档数据持久化存储
- 第十三章 稳定运维,快速交付,以人为本(1)
- POJ2255 Tree Recovery 前序 中序求后序
- Android开源项目1
- 堆排序
- 百度LBS开放平台个性化地图 制作一款独一无二的地图
- IOS 常用的系统应用接口
- 提问技巧(特别适用IT)
- 通过vCenter Server管理多台ESXi主机
- POJ 1815 Friendship | 最小割、最小点割集
- slf4j自动绑定实现类原理