按要求递归建树输出~

#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. count(*)、count(1)、count(column)的区别

    count(*)对行的数目进行计算,包含NULL count(column)对特定的列的值具有的行数进行计算,不包含NULL值. count()还有一种使用方式,count(1)这个用法和count( ...

  2. openresty + lua

    lua语法总结: 1. 导入模块(用require来加载,模块是一个类型为table的全局变量) 导入写好的包,举例如下: 2. lua 数据类型(有8种:nil.boolean.number.str ...

  3. Vue-cli3 项目配置 Vue.config.js( 代替vue-cli2 build config)

    Vue-cli3 搭建的项目 界面相对之前较为简洁 之前的build和config文件夹不见了,那么应该如何配置 如webpack等的配那 只需要在项目的根目录下新建 vue.config.js 文件 ...

  4. git 提交的时候 建立排除文件夹或者文件

    1.在Git的根仓库下 touch .gitignore 2.编辑这个文件

  5. 【做题笔记】P1042 乒乓球

    坑 #1:输入有若干行,但处理的时候要看成一个整体的信息.比如说第一行最后一局比分是 2:1 ,这时不算比完,这个比分要继承到第二行的信息中继续处理. 坑 #2:一局结束,当且仅当其中一方比分大于等于 ...

  6. nfs 动态文件挂载读写权限设置

    nfs 动态文件挂载读写权限设置 待办 ll 命令查看文件夹权限 参考设置共享文件夹https://www.linuxidc.com/Linux/2018-11/155331.htm

  7. springboot 整合GuavaCache缓存

    Guava Cache是一种本地缓存机制,之所以叫本地缓存,是因为它不会把缓存数据放到外部文件或者其他服务器上,而是存放到了应用内存中. Guava Cache的优点是:简单.强大.轻量级. Guav ...

  8. drf解析模块,异常模块,响应模块,序列化模块

    复习 """ 1.接口:url+请求参数+响应参数 Postman发送接口请求的工具 method: GET url: https://api.map.baidu.com ...

  9. Catalyst9K设备介绍

    Catalyst9K系列的里面包含了多款交换机,以及无线控制器,甚至包含了无线AP,如下将简单的介绍这几款产品的情况: 首先,这是一种总体的对应关系: 1.Catalyst9200 Series 主要 ...

  10. nginx autoindex 配置目录浏览功能

    Nginx打开目录浏览功能 yum install httpd-tools -y cd /usr/local/openrestry/nginx/conf/ htpasswd -c passwd adm ...