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内的文件为辅助类,定义了许 ...
随机推荐
- 遗传奥秘的伟大揭秘者:J.Watson
J.Watson的近照: 人们公认,揭秘生命体的遗传奥秘(DNA)是二十世纪最伟大的科技成果之中的一个,或许就是人类最伟大的科技进步(而不是"之中的一个"). 上世纪是人类做出伟大 ...
- js 数组克隆
在JS中,对于对象类型的变量的引用是通过类似C之类的"指针"的方式来操作的,及假设多个变量引用同一个对象,则随意一个变量对对象的操作都会影响到其他的变量. 这个可能不是非常明确,以 ...
- Blur 算法 (Unity 5.0 Shader)
一:简单 Blur 算法 一个像素的颜色值由其邻近的若干像素和自己的颜色值的平均值重新定义,以此达到模糊的效果. 如下图,红色的像素点的值将由它和它周围的24个像素的平均值重新定义.计算的范围一般由一 ...
- webview同步cookies
目前很多android app都内置了可以显示web页面的界面,会发现这个界面一般都是由一个叫做WebView的组件渲染出来的,学习该组件可以为你的app开发提升扩展性. 先说下WebView的一些优 ...
- DNS查询报文实例
2.2 DNS查询报文实例 以www.baidu.com为例,用Wireshark俘获分组,结合2.1的理论内容,很容易看明白的,DNS请求报文如下: 图7 DNS请求报文示例 2.3 DNS回答报文 ...
- NumPy和Pandas常用库
NumPy和Pandas常用库 1.NumPy NumPy是高性能科学计算和数据分析的基础包.部分功能如下: ndarray, 具有矢量算术运算和复杂广播能力的快速且节省空间的多维数组. 用于对整组数 ...
- [BZOJ 3365] Distance Statistics
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3365 [算法] 点分治 [代码] #include <algorithm> ...
- MVC bundle配置文件模板
bundle文件放在应用根目录,命名为 bundle.config 内容模板 <?xml version="1.0" encoding="utf-8"? ...
- Centos7 minimal 系列之Redis共享sessionid(七)
这一章节的内容就当看看,只是个人理解,我想应该是有误的. 一.SessionId sessionid是一个会话的key,浏览器第一次访问服务器会在服务器端生成一个session,有一个sessioni ...
- WPF常用资源
Textbox error template<Style x:Key="ControlBaseStyle" TargetType="{x:Type Control} ...