timus 1136 Parliament(e)
Parliament
Memory limit: 64 MB
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.
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.
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.
Input
Output
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 |
27 |
timus 1136 Parliament(e)的更多相关文章
- timus 1136 Parliament(二叉树)
Parliament Time limit: 1.0 secondMemory limit: 64 MB A new parliament is elected in the state of MMM ...
- ural 1136. Parliament
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1136 题目描述:给定一个按照(左子树-右子树-根)(即先序)遍历序列的树,求其按照 右子 ...
- 1136. Parliament(二叉树)
1136 先由后左 再父 建一个二叉树 #include <iostream> #include<cstdio> #include<cstring> #includ ...
- URAL 1136 Parliament 二叉树水题 BST后序遍历建树
二叉树水题,特别是昨天刚做完二叉树用中序后序建树,现在来做这个很快的. 跟昨天那题差不多,BST后序遍历的特型,找到最后那个数就是根,向前找,比它小的那块就是他的左儿子,比它大的那块就是右儿子,然后递 ...
- URAL 1136 Parliament (DFS)
题意 输入一棵树的后缀表达式(按左-右-中顺序访问),这棵树的每一个结点的数值都比它的左子树结点的数值大,而比它的右子树结点的数值小,要求输出其按右-左-中顺序访问的表达式.所有的数都为正整数,而且不 ...
- codeforces 644A Parliament of Berland
A. Parliament of Berland time limit per test 1 second memory limit per test 256 megabytes input stan ...
- 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行是 ...
- cdoj 1136 邱老师玩游戏 树形背包
邱老师玩游戏 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1136 Desc ...
- [置顶] 【J2SE 】1136 容器之旅
开篇引言 本篇文章我将要详细的介绍一下什么是容器?以及什么是1136?来系统全面的了解容器,以及容器的应用,下面就进入我们的容器之旅吧! 1.什么是容器? 用来存储和组织其他对象的对象.我们也可以这样 ...
随机推荐
- Windows 8.1 Update 2更新了什么?
Windows 8.1的第二个更新将于8月12日(周二补丁日)发布,官方命名是“8月更新”(August Update).但是之前我们已经知道Windows 8.1 Update 2不可能重新提供开始 ...
- SharePoint 2013 开发——Provider-hosted APP准备工作
博客地址:http://blog.csdn.net/FoxDave 后续的内容我们来一步一步开发一个SharePoint Porvider-hosted APP,本篇主要介绍一些准备工作. Sha ...
- 系统的 host文件的作用
有些用户可能已经注意到,我们在上网时除了可使用常规的 http://www.xxx.com或http://www.xxx.com.cn等形式的网站域名之外,还可以使用类似于“202.106.184.2 ...
- 《day12---异常》
//91-面向对象-异常-异常的发生和简单应用. /* 异常: java运行时期发生的问题就是异常. Java中运行时的除了异常Exception含有错误Error. 异常:通常发生后可以有针对性的处 ...
- 重拾java系列一java基础(1)
前言,不知不觉,从接触java到工作至今已有两年的时间,突然感觉自己的基础知识还很薄弱,有些知识虽然知道,但是停留在表面上,没有深挖,或者实践过,感觉掌握的很肤浅,而且时间一长,就觉得忘记了,我觉得这 ...
- java 集合归类
对java的集合一直是停留在使用的角度,没有进行系统的归纳,趁现在比较空闲,归纳一下. 1 集合的层次关系 最顶层的有三个集合,其中一个类,两个接口, 一个类是Arrays,两个接口是Collect ...
- JSP如何在servlet将一个数据模型对象传递给jsp页面
在servlet把对象放到request里,然后jsp里直接通过request取值如 在servlet:(简写了)public void doGet(request,response){UserInf ...
- IOS聊天对话界面
大家好,百忙之中,抽出点空,写个微博,话说好久没写. 最近项目中有碰到写类似微信聊天界面上的效果,特整理了一下,写了一个小的Demo,希望给没头绪的同学们一个参考! 下载地址:http://files ...
- 获取本机IP非127.0.0.1
protected function GetiP() { $preg="/\A((([0-9]?[0-9])|(1[0-9]{2})|(2[0-4][0-9])|(25[0-5] ...
- 【Oracle XE系列之四】创建OracleXE表空间详解
创建OracleXE表空间示例 sqlplus /nolog connect sys as sysdba SQL> create tablespace OPFOCN datafile 'C:\ ...