zoukankan      html  css  js  c++  java
  • POJ 2255 Tree Recovery 树的遍历,分治 难度: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
    ",past);
        }
        return 0;
    }
    
  • 相关阅读:
    pycharm快捷键
    Docker
    Go语言与Elasticsearch
    Celery与APScheduler
    爬虫入门到入狱
    数据分析
    后台管理
    Linux基础与自动化运维
    微信小程序
    Git
  • 原文地址:https://www.cnblogs.com/xuesu/p/4668980.html
Copyright © 2011-2022 走看看