Parliament

Time limit: 1.0 second
Memory limit: 64 MB
A
new parliament is elected in the state of MMMM. Each member of the
parliament gets his unique positive integer identification number during
the parliament registration. The numbers were given in a random order;
gaps in the sequence of numbers were also possible. The chairs in the
parliament were arranged resembling a tree-like structure. When members
of the parliament entered the auditorium they took seats in the
following order. The first of them took the chairman’s seat. Each of the
following delegates headed left if his number was less than the
chairman’s, or right, otherwise. After that he took the empty seat and
declared himself as a wing chairman. If the seat of the wing chairman
has been already taken then the seating algorithm continued in the same
way: the delegate headed left or right depending on the wing chairman’s
identification number.
The
figure below demonstrates an example of the seating of the members of
parliament if they entered the auditorium in the following order: 10, 5,
1, 7, 20, 25, 22, 21, 27.
During
its first session the parliament decided not to change the seats in the
future.
The speech order was also adopted. If the number of the session was odd
then the members of parliament spoke in the following order: the left
wing, the right wing and the chairman. If a wing had more than one
parliamentarian then their speech order was the same: the left wing, the
right wing, and the wing chairman. If the number of the session was
even, the speech order was different: the right wing, the left wing, and
the chairman. For a given example the speech order for odd sessions
will be 1, 7, 5, 21, 22, 27, 25, 20, 10; while for even sessions — 27,
21, 22, 25, 20, 7, 1, 5, 10.
Determine the speech order for an even session if the speech order for an odd session is given.

Input

The first line of the input contains N, the total number of parliamentarians. The following lines contain N integer numbers, the identification numbers of the members of parliament according to the speech order for an odd session.
The total number of the members of parliament does not exceed 3000. Identification numbers do not exceed 65535.

Output

The
output should contain the identification numbers of the members of
parliament in accordance with the speech order for an even session.

Sample

input output
9
1
7
5
21
22
27
25
20
10
27
21
22
25
20
7
1
5
10
Problem Source: Quarterfinal, Central region of Russia, Rybinsk, October 17-18 2001
 

timus 1136 Parliament(e)的更多相关文章

  1. timus 1136 Parliament(二叉树)

    Parliament Time limit: 1.0 secondMemory limit: 64 MB A new parliament is elected in the state of MMM ...

  2. ural 1136. Parliament

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1136 题目描述:给定一个按照(左子树-右子树-根)(即先序)遍历序列的树,求其按照 右子 ...

  3. 1136. Parliament(二叉树)

    1136 先由后左 再父 建一个二叉树 #include <iostream> #include<cstdio> #include<cstring> #includ ...

  4. URAL 1136 Parliament 二叉树水题 BST后序遍历建树

    二叉树水题,特别是昨天刚做完二叉树用中序后序建树,现在来做这个很快的. 跟昨天那题差不多,BST后序遍历的特型,找到最后那个数就是根,向前找,比它小的那块就是他的左儿子,比它大的那块就是右儿子,然后递 ...

  5. URAL 1136 Parliament (DFS)

    题意 输入一棵树的后缀表达式(按左-右-中顺序访问),这棵树的每一个结点的数值都比它的左子树结点的数值大,而比它的右子树结点的数值小,要求输出其按右-左-中顺序访问的表达式.所有的数都为正整数,而且不 ...

  6. codeforces 644A Parliament of Berland

    A. Parliament of Berland time limit per test 1 second memory limit per test 256 megabytes input stan ...

  7. Timus OJ 1997 Those are not the droids you're looking for (二分匹配)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1997 这个星球上有两种人,一种进酒吧至少玩a小时,另一种进酒吧最多玩b小时. 下面n行是 ...

  8. cdoj 1136 邱老师玩游戏 树形背包

    邱老师玩游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1136 Desc ...

  9. [置顶] 【J2SE 】1136 容器之旅

    开篇引言 本篇文章我将要详细的介绍一下什么是容器?以及什么是1136?来系统全面的了解容器,以及容器的应用,下面就进入我们的容器之旅吧! 1.什么是容器? 用来存储和组织其他对象的对象.我们也可以这样 ...

随机推荐

  1. subline快捷键

    折叠所有代码:  按ctrl+k,再按ctrl+1 展开所有代码: 按ctrl+k,再按ctrl+j 折叠此处代码:  ctrl+shift+[ 展开此处代码: ctrl+shift+]

  2. java udp网络编程

    import java.net.*; /* 通过UDP传输发送文字数据 1.建立socket服务 2.提供数据,并封装到数据包中 3.通过sokect服务的发送功能,将数据包发送出去 4.关闭资源 * ...

  3. RPI学习--wiringpi_API

    reference: https://projects.drogon.net/raspberry-pi/wiringpi/functions/ Functions (API) Some of the ...

  4. JAVA之关于This的用法

    JAVA之关于This的用法   业精于勤,荒于嬉:行成于思,毁于随.——韩愈 用类名定义一个变量的时候,定义的应该只是一个引用,外面可以通过这个引用来访问这个类里面的属性和方法,那们类里面是够也应该 ...

  5. 有关WAMPSERVER 环境搭建 如何修改端口,MySQL数据库的修改

    环境搭建 http://share.weiyun.com/88896747fedd4e8b19afebea18f7684c 一.修改Apache的监听端口 1.在界面中选Apache,弹出隐藏菜单选项 ...

  6. 解决C#的64位打包程序,在64位机器上运行出现BadImageFormatException异常。

    转载自:http://msdn.microsoft.com/zh-cn/library/system.badimageformatexception%28v=vs.100%29.aspx BadIma ...

  7. linux基础命令学习(七)samba服务器配置

    samba有五种安全级别,它们分别是: share:不需要samba账户就可登陆samba服务器      user:需要添加samba账户才可以登陆samba服务器      server:由另外一 ...

  8. bootstrap菜单完美解决---原创

    由于bootstrap的各方优点,偶的“点金项目细化分包管理平台”决定采用它.但在使用中遇到了一些问题,比如菜单的问题,这个菜单是用的一个JQuery的一个效果,点击后,所点击的链接处的class要加 ...

  9. grunt 执行

    几天以前,我决定开始启用一个CSS预处理器,找了很久,我选择了SASS并且尝试着去安装它.但是这似乎不是一件简单的事,在安装过程中出现了许多让我始料不及的问题,我很沮丧,但查找了很多资料,我终于找到了 ...

  10. Postfix之mail.cf

    1.# 2. 3.vi /etc/postfix/main.cf #vi编辑postfix配置文件 4.#找到如下配置项酌情修改 5.###### 6.myhostname =  mail.yourd ...