HDU 5444 Elven Postman(dfs)

变压器耦合放大器(低频应用+高频应用) 阅读详情

Elven Postman

Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 315    Accepted Submission(s): 167


Problem Description
Elves are very peculiar creatures. As we all know, they can live for a very long time and their magical prowess are not something to be taken lightly. Also, they live on trees. However, there is something about them you may not know. Although delivering stuffs through magical teleportation is extremely convenient (much like emails). They still sometimes prefer other more “traditional” methods.

So, as a elven postman, it is crucial to understand how to deliver the mail to the correct room of the tree. The elven tree always branches into no more than two paths upon intersection, either in the east direction or the west. It coincidentally looks awfully like a binary tree we human computer scientist know. Not only that, when numbering the rooms, they always number the room number from the east-most position to the west. For rooms in the east are usually more preferable and more expensive due to they having the privilege to see the sunrise, which matters a lot in elven culture.

Anyways, the elves usually wrote down all the rooms in a sequence at the root of the tree so that the postman may know how to deliver the mail. The sequence is written as follows, it will go straight to visit the east-most room and write down every room it encountered along the way. After the first room is reached, it will then go to the next unvisited east-most room, writing down every unvisited room on the way as well until all rooms are visited.

Your task is to determine how to reach a certain room given the sequence written on the root.

For instance, the sequence 2, 1, 4, 3 would be written on the root of the following tree.

 

Input
First you are given an integer T(T≤10) indicating the number of test cases.

For each test case, there is a number n(n≤1000) on a line representing the number of rooms in this tree. n integers representing the sequence written at the root follow, respectively a1,...,an where a1,...,an∈{1,...,n} .

On the next line, there is a number q representing the number of mails to be sent. After that, there will be q integers x1,...,xq indicating the destination room number of each mail.
 

Output
For each query, output a sequence of move ( E or W ) the postman needs to make to deliver the mail. For that E means that the postman should move up the eastern branch and W the western one. If the destination is on the root, just output a blank line would suffice.

Note that for simplicity, we assume the postman always starts from the root regardless of the room he had just visited.
 

Sample Input
  
2 4 2 1 4 3 3 1 2 3 6 6 5 4 3 2 1 1 1
 

Sample Output
  
E WE EEEEE
 

Source
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5449  5448  5447  5446  5445 
 




#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define bug printf("hihi\n")

#define eps 1e-8

typedef long long ll;

using namespace std;

#define mod 1000000007

#define INF 0x3f3f3f3f
#define N 10005

struct stud{
  int to,ne,id;
}e[N*2];

int head[N];
int num;
int a[N],n;
string ans[N];

inline void add(int u,int v,int id)
{
     e[num].to=v;
     e[num].id=id;  //id=0 代表E  1  代表 W
     e[num].ne=head[u];
     head[u]=num++;
}

int dfs(int s,int e)
{
    if(s==e) return a[s];
    if(s>e) return 0;
    int i,j;
    for(i=s+1;i<=e;i++)
        if(a[i]>a[s]) break;
    add(a[s],dfs(s+1,i-1),0);
    add(a[s],dfs(i,e),1);
    return a[s];
}

void pre(int u,string s)
{
      ans[u]=s;
      for(int i=head[u];i!=-1;i=e[i].ne)
      {
          int to=e[i].to;
          if(e[i].id==0)
              pre(to,s+"E");
          else
             pre(to,s+"W");
      }
}
int main()
{
    int i,j,t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        memset(head,-1,sizeof(head));
        num=0;

        dfs(1,n);
        pre(a[1],"");

        int q;
        scanf("%d",&q);
        while(q--)
        {
            scanf("%d",&i);
            cout<<ans[i]<<endl;
        }
    }
     return 0;
}





使用C++编写一个可视化窗口 初学C++时,控制台会给我们提供一个黑窗口,而这篇文章所做的就是:创建一个属于图形界面窗口,而不是使用控制台黑窗口 如图,这是一个标题为XSZY的窗口 看完这篇文章,你想要的窗口大小,图标等都可以自己定义 甚至是在窗口上鼠标的样子,都是可以随意改的 所有有关视窗的基本函数和类型都定义在头文件 <windows.h> 中 我们只需要引用就好了 //引用头文件 windows.h #include<windows.h> 然后定义程序的入口函数main int __stdcall W 阅读详情

相关推荐

Android投屏开发实战:手把手教你用Miracast实现Sink端功能(附完整代码)

本文是一份Android投屏Sink端开发的实战指南,详细讲解了如何利用Miracast协议和Wi-Fi P2P技术,从零构建一个功能完整的屏幕接收器。内容涵盖环境搭建、通过反射启用WFD Sink模式、RTSP协议协商、RTP流接收与解析,以及最终使用IjkPlayer进行音视频解码播放的全过程,并附有核心代码示例。

cherry的博客 878

Elven Postman【二叉树还原】

Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 2652    Accepted Submission(s): 1587   Problem Description Elves are very pe...

有关我的科研的足迹、算法竞赛的日子、生活记录。 411

Linux实战:rMATS可变剪切分析从零到一,避坑指南与结果深度解析

本文详细介绍了在Linux系统上从零开始部署rMATS进行可变剪切分析的完整流程,包括环境搭建、安装避坑指南、参数优化及结果解读。特别针对gfortran依赖、数学库配置等常见问题提供解决方案,并深入解析JC与JCEC结果的差异及可视化技巧,帮助生物信息学研究者高效完成可变剪切分析。

weixin_30394669的博客 408

Elven Postman(BST )

Elven Postman Time Limit: 1500/1000 MS (Java/Others)Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 147Accepted Submission(s): 90 Problem Description Elves are very peculi...

weixin_30951231的博客 127

手把手复现金蝶云星空V8.1文件上传漏洞(附完整POC与修复方案)

本文深度解析金蝶云星空V8.1文件上传漏洞,提供详细的漏洞复现步骤与完整POC,涵盖技术原理、测试环境搭建及验证流程。同时给出多维防护方案,包括官方补丁部署、临时缓解措施和长期安全加固建议,帮助企业有效防范任意文件上传风险。

weixin_30505225的博客 179

79-Halcon-- visualize_object_model_3d 函数功能(交互式3D可视化)

该算子是连接3D数据与决策者的关键可视化桥梁,通过其独特的交互能力和高质量的渲染效果,将复杂的3D信息转化为直观的可视内容,大幅提升工程决策效率和质量。操作符,不仅能在窗口中渲染3D对象,还支持多种交互操作,适用于调试、展示和交互分析场景。本解析将全面探讨其参数功能及工业级应用方案。+几何类型: PointCloud/ TriMesh/CAD。+法线属性: [NX,NY,NZ]+附加数据: Attributes。是Halcon中功能强大的。+顶点属性: [X,Y,Z]+颜色属性: [R,G,B]

weixin_45590420的博客 1205

Elven Postman

题目描述: Elves are very peculiar creatures. As we all know, they can live for a very long time and their magical prowess are not something to be taken lightly. Also, they live on trees. However, there is...

博客 313

从零开始讲DDR(8)——AXI 接口MIG 使用(1)

我们简单拆解了MIG AXI接口中测试文件的整体框架,首先在sim_tb_top.sv文件中例化了DDR模型和example_top。在example_top中,又例化了MIG IP和一个流量产生器ddr4_v2_2_8_axi_tg_top。在ddr4_v2_2_8_axi_tg_top中的主要功能是分别例化了boot_mode_gen,prbs_mode_gen,custom_mode_gen和axi_opcode_gen。

apple_53311083的博客 1587

HDU -5444 Elven Postman

Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Problem Description Elves are very peculiar creatures. As we all know, they can live for a very ...

名字太长容易被发现并打死 431

OpenClaw人人养虾:接入即时通讯平台Zalo

通过 Zalo Official Account(OA,官方账号)API,可以将 OpenClaw 接入 Zalo,实现面向越南用户的自动化客服和互动。

王国平的博客 437

嵌入式AI实战:基于RK3588部署YOLOv11并集成OpenCV实现实时推理(全流程详解)

本文详细介绍了在RK3588芯片上部署YOLOv11目标检测模型的全流程,包括环境搭建、模型转换和实时推理实现。主要内容为:1)通过YOLOv11官方工具将PyTorch模型转为ONNX格式;2)使用RKNN Toolkit2将ONNX模型转换为适配RK3588的RKNN格式;3)在RK3588上结合OpenCV实现实时视频推理功能。教程提供了完整的代码示例和详细步骤说明,帮助开发者快速在边缘设备上部署目标检测模型,实现AI视觉应用的落地。

LXY_LOVE36的博客 212

HDU 5444-二叉树的遍历+建树

题意: 一颗二叉树,有 n 个节点,给出n个节点的先序遍历,即左边小,右边大。之后给出数字m,然后给出m个节点,写出从根节点到m个节 点的路径,往右遍历即往西输出W,往左遍历即往东输出E。 输入: 2 4 2 1 4 3 3 1 2 3 6 6 5 4 3 2 1 1 1 输出: E WE EEEEE 分析: 首先设立节点的属

shao1996的博客 639

数学向量空间的对偶空间解析

对偶空间是线性代数的"进阶语法",它不仅深化了我们对向量空间的理解,还为解决实际问题提供了强大工具。用生活类比解释对偶空间的核心概念,打破"抽象数学"的壁垒;建立对偶空间与原向量空间的直观联系,揭示"对偶"的本质;通过数学推导和代码实现,让读者掌握对偶空间的基本运算;展示对偶空间在科学和工程中的应用,体现其理论价值。范围:本文从有限维实向量空间入手(便于理解),逐步扩展到对偶基、双对偶空间,最后简要提及无限维空间的特殊性。

AI天才研究院 879

DFS hdu5444 Elven Postman

传送门:点击打开链接 题意:类似平衡二叉树,告诉你n个节点,以及n个节点的权值,要求右子节点的权值比根节点权值小,左子节点权值比根节点权值大 思路:按照大小建树,顺带保留上一个节点,然后查询的时候只要直接打印路径就行了 #include #include #include #include #include #include #include #include #include #inclu

qwb的博客 896

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Hdu 5444 Elven Postman dfs

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5444题意:给你n个数字,这n个数字是按照二叉搜索树的节点特性给你的,让你建好这棵二叉搜索树,然后,再给出一些询问,让你回答从根节点到某个节点该怎么走? http://www.cnblogs.com/zyf0163/p/4805218.html?tvd 样例解释的题意题解:dfs: http://www

yxg_123的博客 381

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

hdu 5444 Elven Postman (DFS)

读懂题意就是个水题了。 给一棵树,左儿子权值大于其父亲,右儿子权值小于其父亲。 给出若干询问,输出从根节点到指定节点的路径。 #include #include #include using namespace std; struct Node{ int l,r; }p[1001]; void add(int u,int a) { if(p[u].l==0&&

白学病患者的专栏 681

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

HDU5444(2015长春网赛)——Elven Postman(树的遍历,dfs)

Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1680    Accepted Submission(s): 959 Problem Description Elves are v

say_c_box的博客 484

hdu5444 Elven Postman 二叉树遍历

Elves are very peculiar creatures. As we all know, they can live for a very long time and their magical prowess are not something to be taken lightly. Also, they live on trees. However, there is som

thunderMrbird的博客 877

hdu 5444 Elven Postman 2015 ACM/ICPC Asia Regional Changchun Online

因为number是从东到西填充,所以会构成一颗二叉排序树,且对应前序遍历。 用数组保存所有的节点,用parent和left,right保存节点间的连接关系。通过dfs构造树,再通过dfs查找对应的mail即可。 #include #include #include #include #include #include #include #include #include #include #i

TimeForMiracles 586

hdu5444Elven Postman

每插入一个点就从根开始找应该要插到哪里,如果比父亲结点大插到左边,比父亲结点小插到右边,如果他的父亲结点没有左儿子(比父亲大)或者右儿子(比父亲小),就把这个结点作为他的左儿子(比父亲大)或者右儿子(比父亲小)#include <map> #include <set> #include <stack> #include <queue> #include <cmath> #include <ctime

_zidaoziyan的博客 513

HDU 5444 Elven Postman

思路:这不是一颗裸的排序二叉树么...直接DFS就好啦 #include using namespace std; struct Node { int data; Node*lson; Node*rson; Node(){} Node(int x) { data = x; lson = rson = NULL; } }; void build(Node *root

围巾的ACM博客 516

hdu 5444 Elven Postman 2015 长春网络赛 图论 前序中序构建树

基础图论

ned_chu的博客 644

hdu 5444 Elven Postman长春网赛

5444 2333 建二插排序树,dfs一遍,之后o(1)应对查询 #include<cstdio> #include<cstring> #include<algorithm> #include<queue> using namespace std; const int maxn=1008; struct fuck{ int ...

weixin_34126215的博客 108

hdu 5444 Elven Postman(二叉树的遍历)

Elven Postman Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem Description Elves are very peculiar creatures. As we all know, they can live for a

hexianhao的博客 395

HDU 5444 Elven Postman

题意:给一棵二叉树的中序,前序为升序的1~n,m个查询,求从根走到被查询结点的路径。 解法:模拟一下给前序中序的建树,边建边记路径就可以了……就是建树的时候写着的有点恶心…… 代码: #include<stdio.h> #include<iostream> #include<algorithm> #include<string&...

weixin_30530939的博客 87

hdu5444 Elven Postman 二叉树建树

//给一颗二叉树 , 这颗树是从左到右编号的 , 问 //给出一个树的序列,问从根节点到每一个节点的 //路线 , 向左走是'E' , 向右走是'W' #include<cstdio> #include<cstring> #include<iostream> using namespace std ; const int maxn = 1010

ijbuhv的专栏 537
上一篇: Light oj 1050 - Marbles(概率dp)
下一篇: Light oj 1060 - nth Permutation(dfs 计数)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值