(二叉树)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 ...
随机推荐
- 通过Roslyn构建自己的C#脚本(更新版)(转)
http://www.cnblogs.com/TianFang/p/6939723.html 之前写过文章介绍过如何通过Roslyn构建自己的C#脚本,但那篇文章是参考自Roslyn CTP版 ...
- virtual abstract override new 几点学习
1.Vitual方法和普通方法区别为:继承其的子类可以用override/new在重载此方法,也可以不重载其方法,有方法体(可以写语句),override修饰则调用子类方法2.abstract类中抽象 ...
- 【Java】JVM(六)虚拟机字节码执行引擎
一.概述 执行引擎是虚拟机中最核心的部分之一, 虚拟机自己实现引擎,自己定义指令集和执行引擎的结构体系. 二.栈帧 栈帧包含(1)局部变量表.(2)操作数栈.(3)动态链接.(4)方法返回地址.(5) ...
- docker 配置远程访问
系统: centos 7 Docker version 1.12.6 yum 安装的 #yum install docker docker server在192.168.111.120上 # vim ...
- 70. Climbing Stairs (Array; DP)
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- phpStudy1——PHP文件获取html提交的参数
示例代码: submit.html <!DOCTYPE html> <html> <head> <meta charset="UTF-8" ...
- tell me one of your favorite project-练习英语
原则:引导面试官,不要提很多自己不清楚的东西 [DFS模板] [BFS] q.offer(root)在最上端,q创建后紧随其后 扩展时用的是q.poll()中的head [segment tree] ...
- 坑爹的HP
昨天晚上帮人远程修理电脑,情况是这样的: HP CQ45笔记本, 比较老的机器, win32 xp sp3 系统, 突然发现没有声音了,而且右下角也没有出现小喇叭图标. 处理过程: 1.先查看了控制面 ...
- catkin_make 与cmake
http://blog.csdn.net/zyh821351004/article/details/50388429 1. catkin_make 与cmake的关系 程序在cmake编译的流程: ...
- tp中url地址大小写问题
在tp配置文件中有一个URL_CASE_INSENSITIVE选项,设置为true,表示大小写不敏感. 'URL_CASE_INSENSITIVE' => true