POJ 1363-Rails 简单栈

POJ 1363 Rails (值得一记的栈好题) Rails Time Limit: 1000MS Memory Limit: 10000K 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 possibl 阅读详情

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

 
     题目链接: http://poj.org/problem?id=1363
          
              直接模拟入栈出栈即可:
			for(i=1,k=1;i<=n;){
				for(;i<=n;){                          //入栈
					stack[top++]=i++;
					if(stack[top-1]==chu[p]){top--,p++;break;}
				}
				for(;top>=1&&stack[top-1]==chu[p];top--,p++);//出栈
				for(j=top-2,q=0;j>=0;)
					if(chu[p]==stack[j--]){k=0;break;}//检验是否能出栈
				if(!k){break;}
			}

【 POJ 1363 】Rails 一道把我坑了的简单水题。 不知道为什么深究了,而且弄不清,一直到凌晨,现在北京时间1.14——留作纪念。其实那个先对比还是挺巧妙地。 如果a和b[]不等的话,压栈,相等的话再看栈是不是为空,不空则弹栈,如果空的话直接进入下个比较。 不多说,下面都有注释。 ————————————————————————————————————————题目:RailsRailsTime Limit: 1000 阅读详情

相关推荐

POJ1363 Rails中英文对照翻译与参考解答

POJ1363 Rails中英文对照翻译与参考解答

小谷王左的随笔空间 697

POJ_1363_Rails(栈模拟)

题型:模拟 题意:火车车厢以1~n的顺序开进车站,有一个铁轨用于暂时停放车厢,问是否可以按输入的火车顺序开出。 分析:用栈模拟即可。 1、   先用循环将当前车厢编号放入栈中,若遇到符合驶出序号的则弹出top。 2、   然后再将stack再查一遍,有符合的就pop。 3、   最后剩在stack里的元素只能按部就班的乖乖进行比较了,有就pop,木有就break; 注意点: 1、

Light_starlight 836

把“思考”塞进 1 KB:我用纯 C 语言给单片机手搓了一个微型 Transformer 推理引擎

摘要:本文探讨了在64KB SRAM的MCU(如STM32H743)上部署精简Transformer模型的技术方案。通过将6层Transformer压缩至1层(隐藏维度128)、4-bit KV-Cache量化等优化手段,实现了240KB Flash占用和59KB RAM峰值,推理延迟184ms(400MHz Cortex-M7),准确率96.1%。关键创新包括:手工优化矩阵乘(CMSIS-NN)、查表法Softmax/LayerNorm、权重按Tile重排提升Cache命中率(60%→94%)。

qq_74383080的博客 2923

poj 1363(Stack ) Rails

Rails Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21050   Accepted: 8404 Description There is a famous railway station in PopPush City. Country there is in

twobqn123的专栏 792

10分钟上手YOLOv11:最强姿态估计模型来了,代码开源,效果炸裂!

【10分钟玩转YOLOv11实时姿态估计】🚀 YOLOv11作为YOLO家族最新成员,在速度、精度和易用性上全面升级,尤其适用于姿态估计等复杂视觉任务。本文带您快速掌握: 1️⃣ 核心概念:姿态估计即识别人体17个关键点(如关节部位)并连接成数字骨架,是智能健身、体感游戏等应用的基础。 2️⃣ 技术优势: 超轻量级(最小仅2.9M参数) 极速推理(GPU仅1.7ms) 高精度(COCO mAP@50-95达50%) 3️⃣ 三步实操: ① 安装:pip install ultralytics ② 准备人物

weixin_41246802的博客 1788

行为验证码 AJ-Captcha 使用文档

AJ-Captcha验证码系统集成指南:需添加captcha-spring-boot-starter和Redis依赖,配置Redis连接。核心实现包括Redis缓存服务类CaptchaCacheRedisImpl(含设置、查询、删除验证码等方法)、SPI配置文件及Spring Boot配置类(配置验证码属性和Redis模板)。系统支持验证码生成、校验、防刷等安全功能,适用于Web应用安全验证场景。

千层冷面的博客 2117

POJ1363

/* 顺序栈表示:函数定义 */ /* 顺序栈表示:类型和界面函数声明 */ enum { MAXNUM = 20 /* 栈中最大元素个数,应根据需要定义 */ }; typedef int DataType; /* 栈中元素类型,应根据需要定义 */ struct SeqStack { /* 顺序栈类型定义 */ int t; /* 栈顶位置指示 ...

一只柠檬菜鸡 1579

基于STM32F103的二维码识别项目——OV7670篇

此系列用于记录做过的项目,这篇文章介绍基于STM32F103的二维码识别项目之OV7670FIFO模块。

beyourself_he的博客 4288

【每日一题】poj 1363: Rails(合法出栈顺序)

题目描述(传送门) 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 tu

Josvin 1508

自动化测试工具playwright中文文档-------1.编写测试

Playwright 测试非常简单,它们执行操作,并断言状态是否符合预期。在执行任何操作之前,无需等待任何内容:Playwright 在执行每个操作之前会自动等待一系列可操作性检查通过。此外,在执行检查时也不需要处理竞态条件——Playwright 的断言设计方式能够描述最终需要满足的期望。就这样!这些设计选择允许 Playwright 用户完全忘记他们测试中的不稳定超时和竞态检查。您将学习如何编写第一个测试如何执行操作如何使用断言测试如何在隔离环境中运行如何使用测试钩子。

2301_76646967的博客 2508

避坑指南:群晖DSM 7.X挂载NTFS硬盘,为什么你的SATA口不行?从原理到实战一次讲清

本文深入解析群晖DSM 7.X系统挂载NTFS硬盘的底层原理与实战排查方法,揭示SATA接口权限配置的关键参数(如esataportcfg和internalportcfg),并提供安全修改端口配置的详细步骤。针对不同型号群晖NAS的配置差异,给出替代方案与常见故障排查技巧,帮助用户解决NTFS硬盘挂载问题。

weixin_26757925的博客 256

hoj 1067 Rails //poj1363 Rails 栈的简单应用

//ACM ICPC Central European Regional 1997 /* 简单的栈的应用,可惜WA了好几次 poj上要把最后的while后的cout<<endl;去掉 */ #include <iostream> #include <stack> #include <cstdio> using namespace st...

weixin_30702413的博客 98

FFTW3库在Windows中的安装和使用

Windows 32位平台下载:FFTW Installation on Windows。

weixin_45397344的博客 951

POJ 1363 Rails 模拟栈

来源:http://poj.org/problem?id=1363 题意:有一列火车,车厢编号为1到n,只能由一段进站,另一端出站。现在进站顺序确定,给出一个出站的顺序,判断出站顺序是否可能。 思路:其实就是一个模拟栈的过程,先进后出。但是由于会出现这样的情况,比如说:1 2 3进栈,然后3出栈,然后4 5进栈,所以该出栈的顺序是3 5 4 2 1,所以在模拟的过程中需要注意一下。 还有就是

2009

基于Matlab的无迹卡尔曼滤波惯性导航与DVL组合导航

航天航空领域中的惯性导航是一种基于惯性测量单元(Inertial Measurement Unit,IMU)的导航方法,可以提供航向、速度和位置等信息。深度/速度测量器(Doppler Velocity Log,DVL)是一种常用的传感器,可用于测量水下航行器的速度。通过将DVL与无迹卡尔曼滤波相结合,可以实现高精度的组合导航。本文介绍了基于Matlab的无迹卡尔曼滤波(UKF)惯性导航与DVL组合导航的方法。以上是一种简化的示例代码,您可以根据实际应用需求进行相应的修改和优化。

DevSavantX的博客 418

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

POJ 1363 Rails

POJ 1363 RailsDescription 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

long-long-ago 447

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

[poj] 1363 Rails

[poj] 1363 Rails 【题目】http://poj.org/problem?id=1363 【题意】判断是否能通过栈将顺序列转化为相应队列 【算法】栈模拟 【题解】将未进栈的元素直接输出,之前的元素进栈;判断进栈的元素是不是栈顶,若在栈顶则出栈,反之该队列无法得到。 【注意】标记进栈元素所在栈的位置和元素是否进栈。 注意输出格式 【测试】 无 【代码】 #inclu

464

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

POJ - 1363 - Rails(栈)

POJ 1363.Rails Time Limit: 1000MS      Memory Limit: 10000K Description There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in last century.

在努力! 579

【poj】1363-Rails

#include #include #include const int MAXSIZE = 10000; using namespace std; int trains[MAXSIZE]; int orders[MAXSIZE]; int stacks[MAXSIZE]; int top; int main() { // freopen("b:\\acm\\input.txt","r"

c0de4fun的完美算(nei)法(he)教室-我们仍不知道,那天调用的驱动的名字。 860

POJ 1363 Rails 解题报告

POJ 1363 Rails 解题报告 题目的意思是给出一组数,问你是不是一组合法的出栈序列。 我有两个思路: 1、每个已出栈之后的数且小于此数的数都必须按降序排列。复杂度O(n^2) 2、另一个思路就是直接模拟入栈出栈过程。虽然模拟毫无技巧可言,但复杂度O(n),优于算法1。 1 2#include<cstdio> 3 4intstack[1...

deng530557273的博客 413

POJ1363-Rails

http://poj.org/problem?id=1363 #include<cstdio> #include<stack> using namespace std; int a[1000]; int main(void) { int n; while(scanf("%d",&n),n) { int...

weixin_30685047的博客 195

poj1363 Rails(栈的应用)

题意: 给出火车出站序列,问顺序是否合理,就是判断出栈合理不 算法:模拟栈       1.开辟一个数组存储出栈序列a[..];       2.开辟一个栈 stacks,按顺序存储当前比a[i]小的车厢       3.如果a[i=0 -> n] == j = 0 ->..说明车厢直接出栈       4.如果3不成立,说明下一车厢有可能大于,有可能小于当前车厢编号

水神 1374

POJ1363Rails队列和栈应用

C++实现POJ栈的老题1363 Rails。掌握该处的输入要求。同时练习把队列queue作为函数的形参。这里的问题是:如何把队列作为形参传给函数呢?

阿正的梦工坊 706

【POJ 1363 --- Rails 】栈

【POJ 1363 --- Rails 】栈 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 limi...

来日浅谈的博客 543
上一篇: 纪念我逝去的文曲星
下一篇: 黑白图像-入门级深搜
angle555945
博客等级 码龄15年 66粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值