文件名称:median1363
介绍说明--下载内容均来自于网络,请自行研究使用
pku1363,1、题目简介:
给出一个数n,1~n的所有整数会以从小到大的顺序入栈,但出栈顺序不定,同时给出几组出栈的顺序,要求判断给出出栈顺序是否可能。
2、算法实现思想:
首先建立一系列的Stack操作,入push,pop,isEmpty,top,clear等
将要判断的出栈序列存储至一个数组map中。然后从最大的n开始到1进行循环压栈和出栈处理。从出栈序列map[]的尾部开始,进栈,不断寻找最大的出栈,次大的出栈...最后若栈空则为Yes,否则为No
-pku1363.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
给出一个数n,1~n的所有整数会以从小到大的顺序入栈,但出栈顺序不定,同时给出几组出栈的顺序,要求判断给出出栈顺序是否可能。
2、算法实现思想:
首先建立一系列的Stack操作,入push,pop,isEmpty,top,clear等
将要判断的出栈序列存储至一个数组map中。然后从最大的n开始到1进行循环压栈和出栈处理。从出栈序列map[]的尾部开始,进栈,不断寻找最大的出栈,次大的出栈...最后若栈空则为Yes,否则为No
-pku1363.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
(系统自动生成,下载前可以参看下载内容)
下载文件列表
median1363.cpp