poj1363,这道题是数据结构与算法中的经典问题,给定一组进栈顺序,问栈有多少种出去的顺序。

#include<stdio.h>
#include <stack>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
//    freopen("in.txt","r",stdin);
    int n;
    while(scanf("%d",&n)&&n)
    {
        stack<int> sta;
        ],i;
        ]))
        {
            while(!sta.empty())   sta.pop();
            ]==)
            {
                putchar('\n');break;}
                ; i<n; i++)
                    scanf("%d", &s[i]);
                ;
                ;i<=n;)
                {
                    while(sta.empty()||(!sta.empty()&&sta.top()<s[j]))
                    {
                        sta.push(i++);
                    }
                    while(!sta.empty() && sta.top()==s[j])
                    {
                            j++;sta.pop();
                    }
                    if(!sta.empty() && j<n && sta.top()>s[j])break;
                }
                if(sta.empty()==true) cout <<"Yes" << endl;
                else cout << "No" << endl;
            }
        }
    ;
}

【栈】 poj 1363的更多相关文章

  1. POJ 1363 Rails(栈)

    题目代号:POJ 1363 题目链接:http://poj.org/problem?id=1363 题目原题: Rails Time Limit: 1000MS   Memory Limit: 100 ...

  2. POJ 1363 Rails(栈)

    思路:将出车站的顺序存入数组train,由于入车站的顺序是固定的,为1~N,所以用P表示进站的车,初始为1. 接下来举例说明吧: 原来入站顺序:    1 2 3 4 5 读入的出战顺序: 3 4 2 ...

  3. poj 1363 Rails in PopPush City &&【求堆栈中合法出栈顺序次数】

    问题如下: 问题 B: Rails 时间限制: Sec 内存限制: MB 提交: 解决: [提交][状态][讨论版] 题目描述 There is a famous railway station in ...

  4. poj 1363 火车进站 (栈的应用)

    Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...

  5. poj 1363 Rails (【栈的应用】 刘汝佳的写法 *学习)

    Rails Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25964   Accepted: 10199 Descripti ...

  6. poj 1363 Rails 解题报告

    题目链接:http://poj.org/problem?id=1363 题意:有一列火车,车厢编号为1-n,从A方向进站,向B方向出站.现在进站顺序确定,给出一个出站的顺序,判断出站顺序是否合理. 实 ...

  7. OpenJudg / Poj 1363 Rails

    1.链接: http://poj.org/problem?id=1363 http://bailian.openjudge.cn/practice/1363 2.题目: Rails Time Limi ...

  8. [欧拉回路+手动开栈] poj 1780 Code

    题目链接: http://poj.org/problem? id=1780 Code Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  9. poj 1363

    这是一道数据结构的问题,用到了栈的知识.题目大意讲的是每一次有N辆车从A到B,但是要将车辆的顺序重新排列,可以通过中转站C来辅助排列,但是C符合先进后出的原则,这一点和栈的特性相同. 整个重新排序的过 ...

随机推荐

  1. 一个有用的shell脚本

    #!/bin/bash #if [ $1 -eq null ]; then # echo "please input params1!" # exit #fi #if [ $2 - ...

  2. android 常用

    1:常用之动画(View Animation,Drawable Animation,Property Animation) http://blog.csdn.net/huxueyan521/artic ...

  3. hdu_1253_胜利大逃亡(bfs+剪枝)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1253 题意:三维BFS,不解释 题解:DFS+剪枝会超时,裸BFS会超时,BFS+剪枝才能AC,有点伤 ...

  4. word、pdf、ppt 转为图片

    office word文档.pdf文档.powerpoint幻灯片是非常常用的文档类型,在现实中经常有需求需要将它们转换成图片 -- 即将word.pdf.ppt文档的每一页转换成一张对应的图片,就像 ...

  5. Number-guessing Game

    Number-guessing Game Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Othe ...

  6. how computer boot up?

    The power button activates the power supply in the PC, sending power to the motherboard and other co ...

  7. vs设计界面出现“建控件时出错 响应在此上下文中不可用”

    使用VS2010设计Asp.net时出现: 只有在配置文件或 Page 指令中将 enableSessionState 设置为 true 时,才能使用会话状态.还请确保在应用程序配置的 \\ 节中包括 ...

  8. SQL Server不能通过外部IP访问,解决方法

    SQL Server不能通过外部IP访问,解决方法   版本:SQL server 2008 express with tools   打开配置管理器,开启 TCP,右键属性设置TCP端口:   设置 ...

  9. linux 常用端口

    常用端口 下面的表格中列举了包括在红帽企业 Linux 中的服务.守护进程.和程序所使用的最常见的通信端口.该列表还可以在 /etc/services 文件中找到.要查看由互联网号码分派局(IANA) ...

  10. 将decimal类型的数据转成2.12这样价钱的显示方式

    UnitPrice = string.Format("{0:.00}", m.UnitPrice),