一道把我坑了的简单水题。
不知道为什么深究了,而且弄不清,一直到凌晨,现在北京时间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

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

被折叠的 条评论
为什么被折叠?



