poj1363——Rails
Description
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
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
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的更多相关文章
- POJ1363 Rails 验证出栈序列问题
题目地址: http://poj.org/problem?id=1363 此题只需验证是否为合法的出栈序列. 有两个思路: 1.每个已出栈之后的数且小于此数的数都必须按降序排列.复杂度O(n^2),适 ...
- poj1363 Rails Central Europe 1997
P.S.: 输出换行 三个方法 1.直接按照要求做 根据给的数,需要push,pop哪些数据,具有唯一性 数最多进栈一次,出栈一次 O(n) Source Code Problem: User: co ...
- POJ1363:Rails
Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...
- [poj1363]Rails_模拟_栈
Rails poj-1363 题目大意:判断一个序列是否是1~n的合法出栈序列. 注释:$1\le n\le 10^4$. 想法:开始想到一种想法. 对于一段序列来讲,显然从首元素开始的连续小于尾元素 ...
- Rails sanitize
The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements. T ...
- nginx中error_page没有生效(nginx+passenger+rails)
应用部署方式为 nginx + passenger + rails 当我想要用nginx来默认处理400以上状态时,发现在rails返回respose之后,nginx不会再次执行error_page( ...
- Ruby on Rails 创建https应用
1. 创建证书请求文件条件:私钥+证书签名请求+opensslyum install -y opensslmkdir /root/ssl/ && cd /root/ssl/openss ...
- Rails 5 开发进阶
Rails 5 开发进阶:https://www.gitbook.com/book/kelby/rails-beginner-s-guide/details cancan : http://blo ...
- rails程序文件名命名规范
1 一般文件名是用小写单词加下划线分割,但类的名字用骆驼法.例如 sessions_controller.rb中定义SessionsController. 2 helpers内的文件为辅助类,定义了许 ...
随机推荐
- 41.使用SAX读取XML
main.cpp #include <QtGui> #include <iostream> #include "saxhandler.h" int main ...
- 使用log4net记录日志到数据库(含自定义属性)
日志输出自定义属性! 特来总结一下: 一.配置文件 使用log4写入数据库就不多说了,网上方法很多,自定义字段如下 <commandText value="INSERT INTO db ...
- ubuntu 绘制lenet网络结构图遇到的问题汇总
Couldn't import dot_parser, loading of dot files will not be possible的问题 1 .sudo pip uninstall pypar ...
- Asp.Net Core部署到Linux服务器
从2016年7月, .NET Core1.0 正式发布开始,由于时间问题,我没怎么关注过.NET Core,最近刚抽出点时间研究了下,先讲下如何把ASP.NET Core部署到Linux上吧.这里我用 ...
- 浅谈SpringCloud (三) Ribbon负载均衡
什么是负载均衡 当一台服务器的单位时间内的访问量越大时,服务器压力就越大,大到超过自身承受能力时,服务器就会崩溃.为了避免服务器崩溃,让用户有更好的体验,我们通过负载均衡的方式来分担服务器压力. 我们 ...
- Python3之时间模块详述
Python3之时间模块 time & datetime & calendar 一. 概述 python 提供很多方式处理日期与时间,转换日期格式是一个常见的功能. 时间元组:很多p ...
- Android 高大上的侧滑菜单DrawerLayout,解决了不能全屏滑动的问题
DrawerLayout预览 DrawerLayout主要功能就是 实现侧滑菜单效果的功能,并且可以通过增加一些设置来实现高大上的效果,那么就请看动态图: 注意左上角那个图标,有木有很好玩,哈哈. ...
- Android 让系统自动生成缩略图并写入媒体库
MediaStore.Video.Thumbnails.getThumbnail(ContentResolver cr, long origId, int kind, BitmapFactory.Op ...
- Xcode 下“ did not have any applicable content ”分析及解决
问题的产生 a.新建项目时选的iPhone b.为了做成图片启动,按照惯例去掉了LaunchStoryboard的引用,建了个LaunchImage的资源,属性里随便勾了一个,找了张匹配的图拖了过去 ...
- Eclipse中合并GIT分支
合并GIT分支: 1. 切换到主分支: 2. 右击项目——Team——Merge…: 3. 在弹出的Merge框中选择要合并的分支——Merge: 4. 合并后如果出现冲突,右击项目——Tea ...