HDU5444 Elven Postman
按要求递归建树输出~
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=;
struct node {
int data;
node * left;
node * right;
};
int pre[maxn],in[maxn],T,N,q,x;
void init () {
fill (pre,pre+maxn,);
fill (in,in+maxn,);
}
node * create (int preL,int preR,int inL,int inR) {
if (preL>preR) return NULL;
node * root=new node;
root->data=pre[preL];
int k;
for (k=inL;k<=inR;k++) {
if (in[k]==pre[preL]) break;
}
int numLeft=k-inL;
root->left=create(preL+,preL+numLeft,inL,k-);
root->right=create(preL+numLeft+,preR,k+,inR);
return root;
}
void dfs (node * root,int v) {
if (root->data==v) {
printf ("\n");
return;
}
if (v<root->data) printf ("E"),dfs (root->left,v);
else printf ("W"),dfs (root->right,v);
}
int main () {
scanf ("%d",&T);
while (T--) {
scanf ("%d",&N);
for (int i=;i<=N;i++) in[i]=i;
for (int i=;i<=N;i++) scanf ("%d",&pre[i]);
node * root=create(,N,,N);
scanf ("%d",&q);
for (int i=;i<q;i++) scanf ("%d",&x),dfs (root,x);
}
return ;
}
HDU5444 Elven Postman的更多相关文章
- Elven Postman(二叉树)
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Elven Postman(BST )
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 5444 Elven Postman 二叉树
Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Descrip ...
- hdu 5444 Elven Postman
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Description Elves are very peculia ...
- hdu 5444 Elven Postman(二叉树)——2015 ACM/ICPC Asia Regional Changchun Online
Problem Description Elves are very peculiar creatures. As we all know, they can live for a very long ...
- Hdu 5444 Elven Postman dfs
Elven Postman Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...
- (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)
http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others) ...
- HDU 5444 Elven Postman (2015 ACM/ICPC Asia Regional Changchun Online)
Elven Postman Elves are very peculiar creatures. As we all know, they can live for a very long time ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU 5444 Elven Postman【二叉排序树的建树和遍历查找】
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- python接口自动化之用HTMLTestRunner生成html测试报告
[第一步]:引入HTMLTestRunner包 1.下载HTMLTestRunner,下载地址:http://tungwaiyip.info/software/HTMLTestRunner.html ...
- Linux - Linux中线程为何有PID?
重现 用htop的Tree view(按F5)之后查看线程 参考 https://segmentfault.com/q/1010000003586656 mousycoder的回答 https://u ...
- AcWing 871. 约数之和
#include <iostream> #include <algorithm> #include <unordered_map> #include <vec ...
- 一个超几何函数$_3F_2$的积分
\[\Large\displaystyle \int_0^\infty{_3F_2}\left(\begin{array}c\dfrac58,\dfrac58,\dfrac98\\\dfrac12,\ ...
- 吴裕雄 python 机器学习——局部线性嵌入LLE降维模型
# -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt from sklearn import datas ...
- 微信个人支付接口---YunGouOS 1.1.3 版本发布,新增个人微信/支付宝收款接口
软件接口 https://www.oschina.net/news/113305/yungouos-1-1-3-released 文档说明 https://www.oschina.net/p/Yu ...
- 微服务介绍和springCloud组件
微服务架构模式是:将整个web服务 组织成一系列小的web 服务,这些小的web服务可以进行独立的编译和部署,并通过各自暴露的API接口 进行相互通信,他们相互协作,作为一个整体,为客户提供服务功 ...
- 每天进步一点点------SOPC的Avalon-MM IP核(二) AVALON总线的IP核定制
简介 NIOS II是一个建立在FPGA上的嵌入式软核处理器,除了可以根据需要任意添加已经提供的外设外,用户还可以通过定制用户逻辑外设和定制用户指令来实现各种应用要求.这节我们就来研究如何定制基于Av ...
- unittest 改装框架ascii 排序执行用例,按照自己书写先后顺序执行
设计思路: 获取成员变量class.__dict__.keys() filter过滤符合要求成员,由于3.x成员dict属性是支持有序的 # coding=utf-8import unittestfr ...
- js实现上移下移
直接上代码 //上移 var $up = $(".up") $up.click(function () { var $tr = $(this).parents("tr&q ...