【 POJ 1363 】Rails

本文介绍了POJ 1363题目的详细解析,这是一道关于火车车厢重新排列的逻辑题。文章讨论了解题策略,即如何通过栈的数据结构判断是否能将车厢按特定顺序排列。作者分享了自己在解决此问题时遇到的困难,以及最终解决方案的实现细节。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一道把我坑了的简单水题。
不知道为什么深究了,而且弄不清,一直到凌晨,现在北京时间1.14——留作纪念。

这里写图片描述

其实那个先对比还是挺巧妙地。
如果a和b[]不等的话,压栈,相等的话再看栈是不是为空,不空则弹栈,如果空的话直接进入下个比较。
不多说,下面都有注释。
————————————————————————————————————————

题目:Rails

Rails

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 31401 Accepted: 12201

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 i

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值