(二叉树)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) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 939 Accepted Submission(s): 520
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.

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.
Note that for simplicity, we assume the postman always starts from the root regardless of the room he had just visited.
#include<stdio.h>
#include<string.h> #define N 1005 int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int n, m, x, i, j, a[N]; scanf("%d", &n); for(i=; i<=n; i++)
scanf("%d", &a[i]); scanf("%d", &m);
while(m--)
{
scanf("%d", &x); for(i=; i<=n;)
{
if(a[i]==x) break;
if(a[i]>x)
{
printf("E");
j = i;
while(a[i]>=a[j] && i<=n-) i++;
}
else
{
printf("W");
j = i;
while(a[i]<=a[j] && i<=n-) i++;
}
}
printf("\n");
}
}
return ;
}
(二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)的更多相关文章
- 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 ...
- 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 ...
- (并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )
http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others) Memo ...
- 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 Pro 1008 Elven Postman (BIT,dfs)
Elven Postman Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2015 ACM/ICPC Asia Regional Changchun Online
1001 Alisha’s Party 比赛的时候学长stl吃T.手写堆过. 赛后我贴了那两份代码都过.相差.2s. 于是用stl写水果. # include <iostream> # i ...
- hdu 5444 Elven Postman(根据先序遍历和中序遍历求后序遍历)2015 ACM/ICPC Asia Regional Changchun Online
很坑的一道题,读了半天才读懂题,手忙脚乱的写完(套上模板+修改模板),然后RE到死…… 题意: 题面上告诉了我们这是一棵二叉树,然后告诉了我们它的先序遍历,然后,没了……没了! 反复读题,终于在偶然间 ...
- (线段树 区间查询)The Water Problem -- hdu -- 5443 (2015 ACM/ICPC Asia Regional Changchun Online)
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5443 The Water Problem Time Limit: 1500/1000 MS (Java/ ...
- 2015 ACM/ICPC Asia Regional Changchun Online HDU - 5441 (离线+并查集)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5441 题意:给你n,m,k,代表n个城市,m条边,k次查询,每次查询输入一个x,然后让你一个城市对(u,v ...
随机推荐
- redis-trib.rb报错:/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis (LoadError)
报错如下: /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis ...
- python mysql connector
install pip install mysql-connector-python-rf 报错 从https://dev.mysql.com/downloads/connector/python ...
- 《Blue Flke》第一次作业:团队亮相
1.队名:Blue Flke 团队格言:决心是成功的力量,耐心是成功的保障. 2.团队成员组成: 201571030129/ 王胜海 (组长) 201571030126/ 妥志福 20157103 ...
- moco入门
前提:moco是什么?有什么用 Moco是针对HTTP集成而生的,不过,现在也有人把它用在其它需要一个模拟服务器的场景中.比如,在移动开发中,有人开发一个移动应用,需要有一个远端服务,但在开发时,这个 ...
- referer null
Referer表示超链接源的URL!你想看到实验效果,要从a-->(能过<a href="b.jsp")b页面,然后在B里可以取得Refere参数! String ur ...
- Golang 获取MD5的方法
import ( "crypto/md5" "encoding/hex" ) //生成32位md5字串 func Md5(s string) string { ...
- 可以foreach的 必须继承IEnumable 接口才行
只要是继承IEnumable 都可以用foreach遍历
- hibernate对数据库查询的坑
hibernate对数据库的查询其实有很多种方法,下面我来介绍我知道的两种方法,以及它们可能会遇到的问题,这里前两种都是查询所有结果 最后一种是 使用hibernate查询一条记录. 第一种方法 pu ...
- 清明梦超能力者黄YY(idx数组)
清明梦超能力者黄YY https://www.nowcoder.com/acm/contest/206/I 题目描述 黄YY是一个清明梦超能力者,同时也是一个记忆大师.他能够轻松控制自己在梦中的一切, ...
- 【校招面试 之 C/C++】第8题 C++中的静态绑定与动态绑定
转自:https://blog.csdn.net/chgaowei/article/details/6427731 做了部分修改 为了支持c++的多态性,才用了动态绑定和静态绑定.理解他们的区别有 ...