POJ 1363 Rails
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 21728 | Accepted: 8703 |
Description
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 last block consists of just one line containing 0.
Output
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
题目大意:一串数字从1到n入栈,输入一串数字num,问这串数字的出战顺序能否为num。
#include <stdio.h> int main()
{
int n, num[], Stack[], top = -, nCount = -, index, l;
while(scanf("%d", &n )&& n != )
{
l = ;
index = ;
nCount = -;
top = -;
while(scanf("%d", &num[++nCount]) && num[] != )
{
index++;
if (index == num[nCount])
{
l++;
}
else
{
Stack[++top] = index;
}
for (int i = ; i < n; i++)
{
scanf("%d", &num[++nCount]);
Stack[++top] = ++index;
while(num[l] == Stack[top] && top >= )
{
top--;
l++;
}
}
if (top == -)
{
printf("Yes\n");
}
else
{
printf("No\n");
}
index = ;
nCount = -;
top = -;
l = ;
}
printf("\n");
}
return ;
}
POJ 1363 Rails的更多相关文章
- POJ 1363 Rails(栈)
题目代号:POJ 1363 题目链接:http://poj.org/problem?id=1363 题目原题: Rails Time Limit: 1000MS Memory Limit: 100 ...
- OpenJudg / Poj 1363 Rails
1.链接: http://poj.org/problem?id=1363 http://bailian.openjudge.cn/practice/1363 2.题目: Rails Time Limi ...
- poj 1363 Rails 解题报告
题目链接:http://poj.org/problem?id=1363 题意:有一列火车,车厢编号为1-n,从A方向进站,向B方向出站.现在进站顺序确定,给出一个出站的顺序,判断出站顺序是否合理. 实 ...
- poj 1363 Rails in PopPush City &&【求堆栈中合法出栈顺序次数】
问题如下: 问题 B: Rails 时间限制: Sec 内存限制: MB 提交: 解决: [提交][状态][讨论版] 题目描述 There is a famous railway station in ...
- poj 1363 Rails (【栈的应用】 刘汝佳的写法 *学习)
Rails Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25964 Accepted: 10199 Descripti ...
- POJ 1363 Rails(栈)
思路:将出车站的顺序存入数组train,由于入车站的顺序是固定的,为1~N,所以用P表示进站的车,初始为1. 接下来举例说明吧: 原来入站顺序: 1 2 3 4 5 读入的出战顺序: 3 4 2 ...
- poj 1363
这是一道数据结构的问题,用到了栈的知识.题目大意讲的是每一次有N辆车从A到B,但是要将车辆的顺序重新排列,可以通过中转站C来辅助排列,但是C符合先进后出的原则,这一点和栈的特性相同. 整个重新排序的过 ...
- POJ 1036 Rails 模拟堆栈
水题,主要是思路清晰,判断明确. 记x为A站最前方的车,y表示下一列要进入B站的车厢,初识时,x=1;y=a1;C=[]; 在调度过程中: if(y==0)那么调度成功,退出模拟过程:否则 if(x= ...
- 【栈】 poj 1363
poj1363,这道题是数据结构与算法中的经典问题,给定一组进栈顺序,问栈有多少种出去的顺序. #include<stdio.h> #include <stack> #incl ...
随机推荐
- Hash哈希(二)一致性Hash(C++实现)
一致性Hash 一致性哈希算法在1997年由麻省理工学院提出的一种分布式哈希(DHT)实现算法,设计目标是为了解决因特网中的热点(Hot spot)问题,经常用于分布式.负载均衡等. 原理 一致哈希是 ...
- [新概念51单片机C语言教程·郭天祥] 1、 基础知识必备
目录: 单片机的大致介绍 1-1.通俗定义 1-2.51系列产品 1-3.标号意思 1-4.引脚介绍 1-5.用C语言开 ...
- JsRender for object 语法说明
JsRender 作为一款JavaScript模版引擎,必不可少的会有循环功能,也就是for,但由于JsRender过于灵活,for竟然可以接受object作为循环对象. {{for Array}}和 ...
- [Python爬虫] 在Windows下安装PIP+Phantomjs+Selenium
最近准备深入学习Python相关的爬虫知识了,如果说在使用Python爬取相对正规的网页使用"urllib2 + BeautifulSoup + 正则表达式"就能搞定的话:那么动态 ...
- MySQL 存储过程 定时任务
drop procedure if exists move_track_data; delimiter // create procedure move_track_data() begin ; st ...
- paip.java swt 乱码问题解决
paip.java swt 乱码问题解决 看累挂,Dfile.encoding是gbk的.. 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专 ...
- JSP内置对象总结
前几天学习了javaee中的jsp(Java Server Pages),即java服务器页面,其实就是在html里面写java代码. 一.概述前言 在总结九大对象之前,有必要先搞清楚几个概念:请求, ...
- 深入学习系列--Data Structure--02字符串
字符串可以说是我们实际工作中使用最多的数据类型了,常见的字符串操作包括链接.取子串.格式化等.这部分内容总体来说比较容易理解,最难的部分要数字符串的模式匹配方法了,尤其是KMP算法,需要通过实践加以记 ...
- memset与malloc性能测试
memset与malloc性能测试 测试环境:2.2GHZ.2G内存 memset一段大小为1K的buf,每秒有1200万次:10K的buf,每秒有260万次:100K的buf,每秒有13万次. ma ...
- java 调用微信截图工具