(二叉树)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 ...
随机推荐
- Inspector视图中的get/set使用
using UnityEngine; using System.Collections; public class Test : MonoBehaviour { public int width { ...
- inner outer
left join 是left outer join的简写,left join默认是outer属性的. Inner JoinInner Join 逻辑运算符返回满足第一个(顶端)输入与第二个(底端)输 ...
- css字体加粗
参考 https://zhidao.baidu.com/question/2138403197991538308.html font-weight:bold;
- 2014年可用的TRACKER服务器大全
udp://tracker.openbittorrent.com:80/announceudp://tracker.publicbt.com:80/announcehttp://pubt.net:27 ...
- UVa 1595 Symmetry(set)
We call a figure made of points is left-right symmetric as it is possible to fold the sheet of paper ...
- PTA 习题集5-18 打印选课学生名单(哈希)
假设全校有最多40000名学生和最多2500门课程.现给出每个学生的选课清单,要求输出每门课的选课学生名单. 输入格式: 输入的第一行是两个正整数:N(≤40000),为全校学生总数:K(≤2500) ...
- python之面向对象之类变量和实例变量
#Auther Bob #--*--conding:utf-8 --*-- #这里的变量全部都是实例变量 class Role(object): def __init__(self,name,role ...
- VINS-mono详细解读
VINS-mono详细解读 极品巧克力 前言 Vins-mono是香港科技大学开源的一个VIO算法,https://github.com/HKUST-Aerial-Robotics/VINS-Mono ...
- apache日志里出现GET http://wujieliulan.com/mnews.htmHTTP/1.1解决方法
笔者最近搭建了服务器,Ubuntu 16.04.3 LTS,apache日志里老是出现一些莫名其妙的日志. 好像谁用了我的服务器做代理,日志如下 凭借着小学文化 :) 勉强读懂了汉语拼音wujieli ...
- OCI 编程
一.环境的配置 1.系统环境:要想使用OCI编程需要安装Oracle的客户端,而这个普通的客户端比较大,方便起见,可以安装即时客户端(Instantclient)作为Oracle的访问客户端. 具体 ...