按要求递归建树输出~

#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的更多相关文章

  1. Elven Postman(二叉树)

    Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  2. Elven Postman(BST )

    Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  3. hdu 5444 Elven Postman 二叉树

    Time Limit: 1500/1000 MS (Java/Others)   Memory Limit: 131072/131072 K (Java/Others) Problem Descrip ...

  4. hdu 5444 Elven Postman

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Description Elves are very peculia ...

  5. 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 ...

  6. Hdu 5444 Elven Postman dfs

    Elven Postman Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  7. (二叉树)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)  ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 题解【UVA12097】Pie

    题目描述 输入格式 输出格式 输入输出样例 输入样例#1 3 3 3 4 3 3 1 24 5 10 5 1 4 2 3 4 5 6 5 4 2 输出样例#1 25.1327 3.1416 50.26 ...

  2. 题解【洛谷P5315】头像上传

    本题就是按照题目模拟, 只是要注意一些细节问题. Wrong Answer的主要有以下2个问题: 注意这句话: 在图片上传前,系统会对图片进行如下处理:如果图片的任何一边长度超过了 G ,那么系统会不 ...

  3. nginx-vue项目在window下的部署

    主机->操作系统->window(.net)/Linux->tomcat/nginx(软件反向代理) 1.vue项目打包到dist文件夹(之后把dist文件夹放到服务器就可以了) n ...

  4. Android 服务和广播的使用

    Android 服务和广播的使用 服务的使用 创建服务类 创建一个java文件,取名 mService.java,继承Service. public class mService extends Se ...

  5. 数据存储 csv

    # # 保存csv格式的数据import csv csvFile = open('test.csv','w+',newline='') #文本方式可读写 try: writer = csv.write ...

  6. Linux中 /boot 目录介绍

    转自https://blog.csdn.net/dulin201004/article/details/7396968 一./boot/目录中的文件和目录 Linux系统在本地启动时,目录/boot/ ...

  7. idea中运行ssm 或springboot项目时,project Structure的配置

    ctrl+alt+shift+s进入 project Structure 首先是project选项 Modules 标明source testsource 以及 resource 和 testreso ...

  8. Spring Security技术栈开发企业级认证与授权(一)环境搭建

    本项目是基于慕课网的Spring Security技术栈开发企业级认证与授权,采用IDEA开发,本文章用来记录该项目的学习过程. 慕课网视频:https://coding.imooc.com/clas ...

  9. JSON--WEB SERVICE

    Query ajax webservice:get 和 post 一.GET 方式 客户端 复制代码代码如下: var data = { classCode: "0001"}; / ...

  10. 矩阵-bzoj1898

    This article is made by Jason-Cow.Welcome to reprint.But please post the article's address. BZOJ1898 ...