【习题 6-3 UVA - 536】 Tree Recovery
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
递归题
【代码】
#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的更多相关文章
- 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 ...
- UVa 536 Tree Recovery(二叉树后序遍历)
Little Valentine liked playing with binary trees very much. Her favorite game was constructing rando ...
- UVa 536 Tree Recovery
题意:给出一颗二叉树的前序遍历和中序遍历,输出其后序遍历 用杭电1710的代码改一点,就可以了. #include<iostream> #include<cstdio> #in ...
- UVA 536 Tree Recovery 建树+不建树
题意: 给出先序和中序,求后序. 思路: ①建树然后递归输出. //建树的 #include<iostream> #include<cstdio> #include<qu ...
- UVA - 536 Tree Recovery (二叉树重建)
题意:已知先序中序,输出后序. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio& ...
- 【UVA】536 Tree Recovery(树型结构基础)
题目 题目 分析 莫名A了 代码 #include <bits/stdc++.h> using namespace std; string s1,s2; void buil ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- UVA 536 (13.08.17)
Tree Recovery Little Valentine liked playing with binary trees very much. Her favoritegame was con ...
- Tree Recovery(前序中序求后序)
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14640 Accepted: 9091 De ...
- poj 2255 Tree Recovery 分治
Tree Recovery Description Little Valentine liked playing with binary trees very much. Her favorite g ...
随机推荐
- BFC 和 haslayout
在解释 BFC 是什么之前,需要先介绍 Box.Formatting Context的概念. Box: CSS布局的基本单位 Box 是 CSS 布局的对象和基本单位, 直观点来说,就是一个页面是由很 ...
- cogs 1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292]
1405. 中古世界的恶龙[The Drangon of Loowater,UVa 11292] ★ 输入文件:DragonUVa.in 输出文件:DragonUVa.out 简单对比时间 ...
- Mysql第八天 分区与分表
分区表 主要提供例如以下的特性,或者适合如此场景: 数据量非常大, 或者仅仅有表中最后的部分有热点数据.其它均为历史数据 分区表数据更easy维护,能够对独立的分区删除等操作 分区表的数据能够分布在不 ...
- region实现大纲效果
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 怎样扩展Chromium各层的接口
加入新功能时,可能须要添加各层的接口,接口怎样加?必定须要向Chromium的原则看齐. 首先Chromium的模块设计遵循依赖倒置原则,上层模块依赖于低层模块.低层模块不会依赖上层模块的实现. 再者 ...
- POJ 3252 Round Numbers(组合数学)
Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10223 Accepted: 3726 De ...
- 开源 java CMS - FreeCMS2.3会员积分记录
原文地址:http://javaz.cn/site/javaz/site_study/info/2015/28995.html 项目地址:http://www.freeteam.cn/ 积分记录 从 ...
- xampp 在 centos 中无法启动的解决办法
修改这个文件 vim /opt/lampp/lampp 找到 if egrep "9 " /etc/redhat-release > /dev/null更改为 if ...
- android.graphics.Paint方法setXfermode (Xfermode x...
mPaint = new Paint(); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN)); 常见的Xfermod ...
- 44.delete用法
声明+delete:函数禁止使用.可以使一个类禁止释放