zoukankan      html  css  js  c++  java
  • 【洛谷】P1030 求先序排列

    这是一道图论模板题,用分治的策略即可轻松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;
    }
    

      

  • 相关阅读:
    Linux安装步骤
    Python邮件发送
    拉链表
    Hive
    Shell笔记
    Hadoop入门
    Thinkphp手把手练习
    Shell学习日记
    Linux安装mysql数据库
    Oracle集合操作
  • 原文地址:https://www.cnblogs.com/YMY666/p/7911501.html
Copyright © 2011-2022 走看看