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

【洛谷】P1030 求先序排列

时间:2017-11-28 19:49:17      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:bit   pac   uil   class   names   using   bst   substr   name   

这是一道图论模板题,用分治的策略即可轻松AC!

#include<bits/stdc++.h>
using namespace std;
string st1,st2,s1,s2;

void build(string st1,string st2)
{
	int len = st1.length();
	if (len == 0) return ;
	cout<<st2[len-1];
	int p = st1.find(st2[len-1]);
	s1 = st1.substr(0,p); s2 = st2.substr(0,p);
	build(s1,s2);
	s1 = st1.substr(p+1,len); s2 = st2.substr(p,len-1);
	build(s1,s2);
} 

int main()
{
	cin>>st1>>st2;
	int len = st1.length();
	cout<<st2[len-1];
	int p = st1.find(st2[len-1]);
	s1 = st1.substr(0,p) , s2 = st2.substr(0,p); 
	build(s1,s2);
	s1 = st1.substr(p+1,len); s2 = st2.substr(p,len-1);
	build(s1,s2);
	return 0;
}

  

【洛谷】P1030 求先序排列

标签:bit   pac   uil   class   names   using   bst   substr   name   

原文地址:http://www.cnblogs.com/YMY666/p/7911501.html

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