kami+tree的treechada中文怎么念?

题目链接:Tree Reconstruction题目大意:给定一棵树的DFS序和BFS序,求这棵树。解题思路:先跑一遍BFS,并将每个节点映射成BFS序,由于BFS的特性,其序号越大,离根结点的距离相等或更远。接着遍历DFS序,并用栈维护结点之间的关系,若当前序号比栈顶元素大,则该结点为孩子结点,否则pop掉栈顶元素继续与下一个元素比较。由于只告诉BFS和DFS序所建立的树并不唯一,所以我们强制认为只比当前结点序号大1的结点为该结点的兄弟结点。代码如下:#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 0x3f3f3f3f;
const int maxn = 2e4 + 15;
int pos[1005];
int main(){
ios::sync_with_stdio(false);
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif
int n, node, root;
while(cin >> n){
vector<int> chd[1005];
for(int i = 1; i <= n; i++){
cin >> node;
pos[node] = i;
}
cin >> node;
stack<int> sta;
sta.push(node);
root = node;
for(int i = 2; i <= n; i++){
cin >> node;
while(1){
int e = sta.top();
if(e == root
pos[node] > pos[e] + 1){
chd[e].push_back(node);
sta.push(node);
break;
}
else
sta.pop();
}
}
for(int i = 1; i <= n; i++){
cout << i << ":";
for(auto e : chd[i]){
cout << ' ' << e;
}
cout << endl;
}
}
return 0;
}

选择擅长的领域继续答题?
{@each tagList as item}
${item.tagName}
{@/each}
手机回答更方便,互动更有趣,下载APP
提交成功是否继续回答问题?
手机回答更方便,互动更有趣,下载APP
展开全部I'm sitting here in a boring room.我坐在这——一间空屋子里it's just another rainy sunday afternoon。这也只不过是另一个下雨的周日下午。i'm waisting my time, i got nothing to do.除了消磨时间我没什么事情可做。i'm hanging around, i'm waiting for you。我四处张望,我在等待你的到来。but nothing ever happens, and i wonder.但是好像什莫事情也未曾发生,我不知道。i'm driving around in my car.我开着车出去兜风。i'm driving too fast, i'm drving too far。我把车开得很快,开了很远。i'd like to change my point of view。我想换种方式生活,换个角度看世界。i felt so lonely, i'm waiting for you.我感觉到如此孤单,我在等你回来。but nothing ever happens, and i wonder.但是什莫事也未曾发生,我不明白为什莫会这样。i wonder how, i wonder why。我不知道怎莫办,我不知道为什莫会这样。yesterday you told me about the blue, blue sky.昨天你还给我讲那蓝蓝的天空会多莫美丽,生活会多莫美好。and all that i can see is just a yellow lemon tree。但是我看见的只有一株柠檬树。i'm turning my head up and down。i'm turning, turning, turning, turning, turning around.我摆动着我的头,上下上下,不停的摆动着我的头。我前后左右的看。(我左看右看上看下看)and all that i can see is just another yellow lemon tree.(不管我怎莫看)它也只是一株黄色的柠檬树。i'm sitting here, and i miss the power.我坐在这里,身上没有了一丝力气。i'd like to go out taking a shower。我想出去展示一下我自己。but there's a heavy cloud inside my mind.但是我心中有着顾虑。有一片阴云载我心中挥之不去。i feel so tired, and put myself into bed.我感觉如此的疲惫,回到了家里把自己扔到了床上。where nothing ever happens, and i wonder。也许什莫也没发生过,谁知道呢?i'm stepping around in a desert of joy.我在快乐的沙漠中踱步。baby, anyhow i get another toy。宝贝,无论如何我要找到另一个玩具。and everthing will happen, and you wonder。然后,所有事情都会发生,然而这一切你不会知道。and all that i can see is just another lemon tree.我所有能够看见的只是另一株柠檬树。and all that i can see,我所有能够看见and all that i can see, 我所有能够看见的and all that i can see is just a yellow lemon tree我所有能够看见的只是另一株柠檬树。已赞过已踩过你对这个回答的评价是?评论
收起推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
为你推荐:
下载百度知道APP,抢鲜体验使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。扫描二维码下载
×个人、企业类侵权投诉
违法有害信息,请在下方选择后提交
类别色情低俗
涉嫌违法犯罪
时政信息不实
垃圾广告
低质灌水
我们会通过消息、邮箱等方式尽快将举报结果通知您。说明
做任务开宝箱累计完成0
个任务
10任务
50任务
100任务
200任务
任务列表加载中...

我要回帖

更多关于 treechada中文怎么念 的文章