码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2255 Tree Recovery 树的遍历,分治 难度:0

时间:2015-07-23 00:15:16      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:

http://poj.org/problem?id=2255

#include<cstdio>
#include <cstring>
using namespace std;
const int maxn = 27;
char pre[maxn],in[maxn];
char past[maxn];
void tre(int ps,int pe,int is,int ie,int& ind)
{
    int lnum = strchr(in,pre[ps]) - in - is;

    if(lnum != 0)
    {
        tre(ps + 1,ps + 1 + lnum,is ,is + lnum,ind);
    }
    if(is + lnum + 1 != ie)
    {
        tre(ps + 1 + lnum,pe,is + lnum + 1 ,ie,ind);
    }
    past[ind++] = pre[ps];
}
int main()
{
    while(scanf("%s%s",pre,in) == 2)
    {
        int ind = 0;
        int len = strlen(pre);
        tre(0,len,0,len,ind);
        past[len] = 0;
        printf("%s\n",past);
    }
    return 0;
}

 

POJ 2255 Tree Recovery 树的遍历,分治 难度:0

标签:

原文地址:http://www.cnblogs.com/xuesu/p/4668980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!