【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

递归题

【代码】

#include <bits/stdc++.h>
using namespace std; const int N = 300; string s1, s2;
int n, idx;
int g[N][2]; int dfs(int l, int r) {
int temp = l;
for (int i = l; i <= r; i++) {
if (s2[i] == s1[idx]) {
temp = i;
}
}
idx++; if (l <= temp - 1) {
g[(int)s2[temp]][0] = dfs(l, temp-1);
} if (temp + 1 <= r) {
g[(int)s2[temp]][1] = dfs(temp + 1, r);
}
return s2[temp];
} void dfs2(int x) {
if (g[x][0]) {
dfs2(g[x][0]);
}
if (g[x][1]) {
dfs2(g[x][1]);
}
cout << (char)x;
} int main() {
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0), cin.tie(0);
while (cin >> s1 >> s2) {
memset(g, 0, sizeof g);
n = s1.size();
idx = 0;
dfs2(dfs(0, n - 1));
cout << endl;
}
return 0;
}

【习题 6-3 UVA - 536】 Tree Recovery的更多相关文章

  1. UVa 536 Tree Recovery | GOJ 1077 Post-order (习题 6-3)

    传送门1: https://uva.onlinejudge.org/external/5/536.pdf 传送门2: http://acm.gdufe.edu.cn/Problem/read/id/1 ...

  2. UVa 536 Tree Recovery(二叉树后序遍历)

    Little Valentine liked playing with binary trees very much. Her favorite game was constructing rando ...

  3. UVa 536 Tree Recovery

    题意:给出一颗二叉树的前序遍历和中序遍历,输出其后序遍历 用杭电1710的代码改一点,就可以了. #include<iostream> #include<cstdio> #in ...

  4. UVA 536 Tree Recovery 建树+不建树

    题意: 给出先序和中序,求后序. 思路: ①建树然后递归输出. //建树的 #include<iostream> #include<cstdio> #include<qu ...

  5. UVA - 536 Tree Recovery (二叉树重建)

    题意:已知先序中序,输出后序. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio& ...

  6. 【UVA】536 Tree Recovery(树型结构基础)

    题目 题目     分析 莫名A了     代码 #include <bits/stdc++.h> using namespace std; string s1,s2; void buil ...

  7. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

  8. UVA 536 (13.08.17)

     Tree Recovery  Little Valentine liked playing with binary trees very much. Her favoritegame was con ...

  9. Tree Recovery(前序中序求后序)

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14640   Accepted: 9091 De ...

  10. poj 2255 Tree Recovery 分治

    Tree Recovery Description Little Valentine liked playing with binary trees very much. Her favorite g ...

随机推荐

  1. 客户端本地存储(cookie、web Storage、vuex)选择

    一.cookie .localStorage .sessionStorage .vuex 比较 cookie   4K    有时效性    可服务器传递 cookie是由服务器产生,存储在客户端的一 ...

  2. 51nod 最大子矩阵和

    一个M*N的矩阵,找到此矩阵的一个子矩阵,并且这个子矩阵的元素的和是最大的,输出这个最大的值. 我们可以降维,枚举矩形的长,然后算出一个一维数组,然后就转化成了最大字段和问题 #include< ...

  3. PHP抓取网页内容的几种方法

    方法1: 用file_get_contents 以get方式获取内容 <?php $url='http://www.domain.com/?para=123'; $html = file_get ...

  4. 洛谷 P1581 A+B Problem(升级版)

    P1581 A+B Problem(升级版) 题目背景 小明这在写作业,其中有一道A+B Problem ,他想啊想啊想,就是想不出来,于是就找到了会编程的你...... 题目描述 这里的A+B是很奇 ...

  5. pat(A) 1065. A+B and C (64bit) (java大数)

    代码: import java.util.*; import java.math.*; public class Main { public static void main(String args[ ...

  6. php 图片局部打马赛克

    php 图片局部打马赛克 原理: 对图片中选定区域的每一像素,添加若干宽度及高度,生成矩型.而每一像素的矩型重叠在一起.就形成了马赛克效果. 本例使用GD库的imagecolorat获取像素颜色,使用 ...

  7. JAVA多态学习2

    好啦,这里紧接着上次没说的向下转型,请读者结合上次讨论的向上转型的样例一起探讨(事实上本次代码也有加上,放心). 我们这里希望从向下转型会出现的两种基本情况进行探讨 package downcasti ...

  8. SuSe Linux Enterprise Server 10 With Sp2 安装过程图解

    SuSe Linux Enterprise Server 10 With Sp2 安装过程图解 650) this.width=650;" style="border-right- ...

  9. Vue 实现分页+输入框关键字筛选

    分页的实现(Vue+Element)+输入框关键字筛选 1.这里用的是Element 自带的分页组件 <template> <div class="sales-table& ...

  10. 用css让元素隐藏的几种办法

    display:none;   //能隐藏并不占空间 visibility:hidden;  //隐藏但占据空间 opacity:0; position:absolute 移动到不在页面显示的地方