Description

There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century. Unfortunately, funds were extremely limited that time. It was possible to establish only a surface track. Moreover, it turned out that
the station could be only a dead-end one (see picture) and due to lack of available space it could have only one track. 




The local tradition is that every train arriving from the direction A continues in the direction B with coaches reorganized in some way. Assume that the train arriving from the direction A has N <= 1000 coaches numbered in increasing order 1, 2, ..., N. The
chief for train reorganizations must know whether it is possible to marshal coaches continuing in the direction B so that their order will be a1, a2, ..., aN. Help him and write a program that decides whether it is possible to get the required order of coaches.
You can assume that single coaches can be disconnected from the train before they enter the station and that they can move themselves until they are on the track in the direction B. You can also suppose that at any time there can be located as many coaches
as necessary in the station. But once a coach has entered the station it cannot return to the track in the direction A and also once it has left the station in the direction B it cannot return back to the station. 


Input

The input consists of blocks of lines. Each block except the last describes one train and possibly more requirements for its reorganization. In the first line of the block there is the integer N described above. In each of the next lines of the block there
is a permutation of 1, 2, ..., N. The last line of the block contains just 0. 



The last block consists of just one line containing 0.

Output

The output contains the lines corresponding to the lines with permutations in the input. A line of the output contains Yes if it is possible to marshal the coaches in the order required on the corresponding line of the input. Otherwise it contains No. In addition,
there is one empty line after the lines corresponding to one block of the input. There is no line in the output corresponding to the last ``null'' block of the input.

Sample Input

5
1 2 3 4 5
5 4 1 2 3
0
6
6 5 4 3 2 1
0
0

Sample Output

Yes
No Yes
#include<stdio.h>
int main()
{
int input[1005],output[1005],cnt,j,i,n;
while(scanf("%d",&n),n) //输入列车节数
{
while(scanf("%d",&output[0]),output[0])
{
for(j=1; j<n; j++)
scanf("%d",&output[j]); //输入出栈的顺序
for(cnt=1,j=0,i=0; cnt<=n;) //cnt表示对进站时列车编号,并在编号完毕后退出
{
input[i]=cnt;
//在编号时,假设遇到相应位置同样的出站编号。进入循环。进站顺序向后。出站顺序向前相应,相应成功继续循环
while(input[i]==output[j])
{
i--;
j++; //每当相应成功。位置向后移。看是否还能相应
//i==-1时,代表进站的车厢相应到达顶端,之前的车厢一定相应成功,代表从刚进入循环时到这里所经历的车厢可以成功出站
if(i==-1)
break;
}
i++;
cnt++;
}
if(j==n) //假设成功出站。那么对于出站列车,每节车厢都相应成功
printf("Yes\n");
else
printf("No\n");
}
printf("\n");
}
}

poj1363——Rails的更多相关文章

  1. POJ1363 Rails 验证出栈序列问题

    题目地址: http://poj.org/problem?id=1363 此题只需验证是否为合法的出栈序列. 有两个思路: 1.每个已出栈之后的数且小于此数的数都必须按降序排列.复杂度O(n^2),适 ...

  2. poj1363 Rails Central Europe 1997

    P.S.: 输出换行 三个方法 1.直接按照要求做 根据给的数,需要push,pop哪些数据,具有唯一性 数最多进栈一次,出栈一次 O(n) Source Code Problem: User: co ...

  3. POJ1363:Rails

    Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...

  4. [poj1363]Rails_模拟_栈

    Rails poj-1363 题目大意:判断一个序列是否是1~n的合法出栈序列. 注释:$1\le n\le 10^4$. 想法:开始想到一种想法. 对于一段序列来讲,显然从首元素开始的连续小于尾元素 ...

  5. Rails sanitize

    The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements. T ...

  6. nginx中error_page没有生效(nginx+passenger+rails)

    应用部署方式为 nginx + passenger + rails 当我想要用nginx来默认处理400以上状态时,发现在rails返回respose之后,nginx不会再次执行error_page( ...

  7. Ruby on Rails 创建https应用

    1. 创建证书请求文件条件:私钥+证书签名请求+opensslyum install -y opensslmkdir /root/ssl/ && cd /root/ssl/openss ...

  8. Rails 5 开发进阶

    Rails 5 开发进阶:https://www.gitbook.com/book/kelby/rails-beginner-s-guide/details   cancan : http://blo ...

  9. rails程序文件名命名规范

    1 一般文件名是用小写单词加下划线分割,但类的名字用骆驼法.例如 sessions_controller.rb中定义SessionsController. 2 helpers内的文件为辅助类,定义了许 ...

随机推荐

  1. VMware虚拟机无法识别U盘解决方式

    1. 本机情况: Winxp操作系统(相同应该适用于win7),VMware虚拟机.虚拟机版本号:VMware 10.安装Ubuntu14.04.现要求在主机上插入U盘.在虚拟机中显示. 2. 遇到问 ...

  2. Linux体验之旅(一)——制作U启,安装rhel-server-6.3

    U启制作: 双击UltraISO: 点击文件→打开: 选择rhel-server6.3 点击启动→选择写入硬盘映像 最后选择格式化优盘→写入→完毕 注意:启动盘制作完毕后一定记得将rhel-serve ...

  3. poj - 1159 - Palindrome(滚动数组dp)

    题意:一个长为N的字符串( 3 <= N <= 5000).问最少插入多少个字符使其变成回文串. 题目链接:http://poj.org/problem?id=1159 -->> ...

  4. OzymanDNS 使用——perl 5.22没有成功。。。

    最初官方的代码没有找到,但是发现github里貌似有: git clone https://github.com/splitbrain/dnstunnel.git 源码是perl写的,需要安装一些pe ...

  5. 使用VMware搭建3台一模一样的Linux虚拟机

    转自:https://www.linuxidc.com/Linux/2014-08/105909.htm 简介:VMware可以在个人本地一台笔记本机器上同时运行二个或更多Windows.DOS.LI ...

  6. Spark SQL概念学习系列之用户自定义函数

    不多说,直接上干货! 用户自定义函数 注册udf 我们可以使用Spark 支持的编程语言编写好函数,然后通过Spark SQL 内建的方法传递进来,非常便捷地注册我们自己的UDF 在Scala 和Py ...

  7. 从零开始学习SVG

    1 什么是SVG? MDN中的定义是:SVG即可缩放矢量图形(Scalable Vector Graphics,SVG),是一种用来描述二维矢量图形的 XML 标记语言. 简单地说,SVG 面向图形, ...

  8. (转载)Android项目实战(三十二):圆角对话框Dialog

    Android项目实战(三十二):圆角对话框Dialog   前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对话 ...

  9. 任何抛开业务谈大数据量的sql优化都是瞎扯

    周三去某在线旅游公司面试.被问到了一个关于数据量大的优化问题.问题是:一个主外键关联表,主表有一百万数据,外键关联表有一千万的数据,要求做一个连接. 本人接触过单表数据量最大的就是将近两亿行历史数据( ...

  10. day09-1 列表,元祖的内置方法

    目录 列表类型的内置方法 作用 定义方式 方法 优先掌握 需要掌握 储存一个值or多个值 有序or无序?(有序:有索引, 无序:无索引) 可变or不可变(可变:值变id不变,不可变:值变id也变) 元 ...