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 cultu
HDU - 5444 Elven Postman (根节点到指定节点的路径)
这篇博客讲述了精灵世界中的一种特殊邮递方式,尽管有魔法传送,但有时他们仍使用传统方式递送邮件。精灵住在类似二叉树的树上,房间编号从东到西。邮差需要根据根节点上的序列来确定如何将邮件送到指定房间。问题转化为从根节点到目标节点的路径。给定树的节点数和根节点序列,以及需要递送的邮件数量和目标房间,需要输出邮差的移动方向(E或W)。解决方案包括建立二叉树并记录路径。
摘要由CSDN通过智能技术生成