日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

POJ2255Tree Recovery

發(fā)布時間:2024/4/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ2255Tree Recovery 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2255:Tree Recovery

題目分析:使用前序序列和中序序列構(gòu)造后序序列的題。當(dāng)時面微軟實(shí)習(xí)生的時候還問過這個。

前序的第一個節(jié)點(diǎn)就是后序的最后一個節(jié)點(diǎn),且該節(jié)點(diǎn)把中序序列劃分成左右兩個子樹。中序的這兩個子樹對應(yīng)著前序的兩個子樹,他們的長度分別相等。

代碼如下:

#include <iostream> #include <string> using namespace std; string getPost(string pre,string in){if(pre.length() == 0)return "";//注意邊界條件if(pre.length() == 1)return pre;char root = pre[0];int len = in.find(root);return getPost(pre.substr(1,len),in.substr(0,len)) + getPost(pre.substr(1+len),in.substr(1+len)) + root; } int main(){string pre,in;while(cin>>pre){cin>>in;cout<<getPost(pre,in)<<endl;}return 0; }題目:

時間限制: 1000ms 內(nèi)存限制: 65536kB
描述
Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital letters in the nodes.
This is an example of one of her creations:


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?D
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? / \
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/ ? \
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? B ? ? E
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/ \ ? ? \
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? / ? \ ? ? \
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?A ? ? C ? ? G
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?/
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? F


To record her trees for future generations, she wrote down two strings for each tree: a preorder traversal (root, left subtree, right subtree) and an inorder traversal (left subtree, root, right subtree). For the tree drawn above the preorder traversal is DBACEGF and the inorder traversal is ABCDEFG.
She thought that such a pair of strings would give enough information to reconstruct the tree later (but she never tried it).


Now, years later, looking again at the strings, she realized that reconstructing the trees was indeed possible, but only because she never had used the same letter twice in the same tree.
However, doing the reconstruction by hand, soon turned out to be tedious.
So now she asks you to write a program that does the job for her!


輸入
The input will contain one or more test cases.
Each test case consists of one line containing two strings preord and inord, representing the preorder traversal and inorder traversal of a binary tree. Both strings consist of unique capital letters. (Thus they are not longer than 26 characters.)
Input is terminated by end of file.


輸出
For each test case, recover Valentine's binary tree and print one line containing the tree's postorder traversal (left subtree, right subtree, root).
樣例輸入
DBACEGF ABCDEFG
BCAD CBAD
樣例輸出
ACBFGED
CDAB

轉(zhuǎn)載于:https://www.cnblogs.com/zhuyuanhao/archive/2012/10/03/3262878.html

總結(jié)

以上是生活随笔為你收集整理的POJ2255Tree Recovery的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产鲁鲁视频在线观看特色 | 东方av在线免费观看 | 激情欧美在线 | 污黄视频网站 | 国产69精品久久久久999小说 | 久久久久久久久久电影 | 日韩毛片在线 | 日韩极品视频 | 白石茉莉奈中文字幕在 | 国产在线观看免费播放 | 99热在线免费观看 | 欧美日本激情 | 亚洲天堂网站在线 | 特大黑人巨人吊xxxx | 天堂va在线 | 少妇高潮迭起 | 国产xxxxx在线观看 | 国产剧情在线 | 欧美一区影院 | 爱爱一级 | 欧美一二三 | 欧美成人三区 | 黄色在线网站 | 91视频国产免费 | 三上悠亚中文字幕在线播放 | 欧美色图片区 | 天天综合天天做天天综合 | 色婷婷香蕉在线一区二区 | 爱情岛论坛成人 | 天天色播 | 97se.com | 婷婷丁香综合 | xxxxwww一片 | 女的被男的操 | 日韩久久久精品 | 日韩一区二区三区视频在线 | 亚欧美色图| 黄色网址免费 | 苍井空亚洲精品aa片在线播放 | 黄色免费网页 | 精品欧美色视频网站在线观看 | 欧美日韩不卡一区二区 | 57pao国产成永久免费视频 | 琪琪色综合网 | 国产午夜成人久久无码一区二区 | 超碰自拍 | 成人片在线视频 | 激情黄色小说网站 | 国产不卡av在线 | 色综合天天干 | 久久久夜色 | 国产视频999 | 999视频在线播放 | 丁香婷婷成人 | 大吊一区二区三区 | 成人精品免费视频 | 久久免费看片 | 毛片毛片毛片毛片毛片毛片 | 中文字幕乱码一二三区 | 综合在线观看 | 久久综合资源 | 欧美自拍视频在线观看 | 亚洲福利影视 | 日日操日日干 | 99人妻碰碰碰久久久久禁片 | 人妖天堂狠狠ts人妖天堂狠狠 | 久久国产成人精品国产成人亚洲 | 红桃视频成人在线 | 日日cao | 在线观看欧美成人 | 玖玖爱在线观看 | 青青青草国产 | 午夜人体视频 | 麻豆影视在线免费观看 | 91九色丨porny丨国产jk | 九九爱精品 | 免费污片软件 | 在线观看亚洲成人 | 国产精品视频免费看 | 啪啪网视频 | 窝窝午夜看片 | 天天舔天天射 | 国产激情av | 免费国偷自产拍精品视频 | 欧美精品福利 | 精品人妻少妇一区二区三区 | 红桃视频隐藏入口 | 国产精品.xx视频.xxtv | 丁香花五月天 | 无码人妻丰满熟妇区毛片蜜桃精品 | 国产美女主播视频 | 韩国三级中文字幕hd久久精品 | 欧美三级一区二区 | 成人黄色一区二区三区 | 一级美女黄色片 | 日本妈妈3 | 亚洲一二区在线 | 久久午夜夜伦鲁鲁一区二区 | 91美女在线 |