this problem is a very classic problem which can use stack to solve. the problem can be searched through many source site.

#include<cstdio>
#include<stack>//表明要调用关于栈的文件吧;
using namespace std;
const int maxn=+;
使用栈
int n,target[maxn];
int main()
{
while(scanf("%d",&n)==)
{
stack<int> s;//生成一个元素为int的栈吧;
int A=,B=;
for(int i=;i<=n;i++)
scanf("%d",&target[i]);//读入出栈顺序;
int ok =;
while(B<=n)
{
if(A==target[B]){A++;B++;}//进等于出就直接出;
else if(!s.empty()&&s.top()==target[B])
{s.pop();B++;}//如果S不为空栈并且s的栈顶元素正好为需要的B元素就直接把顶端元素放出去;
else if(A<=n)s.push(A++);//还有合法的未进栈元素就让其进栈;
else {ok=;break;}
}
printf("%s\n",ok?"Yes":"No");
}
return ;
}

the railway problem(the example of stack)的更多相关文章

  1. ZOJ Problem Set - 1004-Anagrams by Stack

     唉!先直接上源码吧!什么时候有时间的再来加说明. #include<iostream> #include<vector> #include<stack> #i ...

  2. ZOJ 1004 Anagrams by Stack

    Anagrams by Stack 题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1004 题意:通过堆栈实现将一 ...

  3. 【LEETCODE OJ】Binary Tree Postorder Traversal

    Problem Link: http://oj.leetcode.com/problems/binary-tree-postorder-traversal/ The post-order-traver ...

  4. init/main.c

    /* * linux/init/main.c * * Copyright (C) 1991, 1992 Linus Torvalds */ #include <stdarg.h> #inc ...

  5. Lua 架构 The Lua Architecture

    转载自:http://magicpanda.net/2010/10/lua%E6%9E%B6%E6%9E%84%E6%96%87%E6%A1%A3/ Lua架构文档(翻译) 十 102010 前段时间 ...

  6. UVa120 - Stacks of Flapjacks

    Time limit: 3.000 seconds限时:3.000秒 Background背景 Stacks and Queues are often considered the bread and ...

  7. UVa OJ 120

    Background背景 Stacks and Queues are often considered the bread and butter of data structures and find ...

  8. hdu4338 Simple Path

    Everybody knows that totalfrank has absolutely no sense of direction. Getting lost in the university ...

  9. gdb-example-ncurses

    gdb-example-ncurses http://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html 1. The Prob ...

随机推荐

  1. DataTable转List<Model>通用类【实体转换辅助类】

    /// <summary> /// DataTable转List<Model>通用类[实体转换辅助类] /// </summary> public class Mo ...

  2. ARM指令集----杂项指令

    ARM指令集可以分为6类,即是跳转指令,数据处理指令,程序状态传输指令,Load.Store指令,协处理器指令和异常中断指令 跳转指令: 在ARM中有两种方式可以实现程序的跳转,一种是跳转指令,另一种 ...

  3. 初识MFC,WinForm,WPF,Q&#39;t

    MFC和QT是C++中常见的GUI框架,而WinForm和WPF是C#中常用的框架,不过我们一般很少叫WinForm框架,可能直接叫图形控件类库更多点.反正只是个称呼罢了,爱咋叫就咋叫.另外WinFo ...

  4. 基于Maven管理的Mapreduce程序下载依赖包到LIB目录

    1.Mapreduce程序需要打包作为作业提交到Hadoop集群环境运行,但是程序中有相关的依赖包,如果没有一起打包,会出现xxxxClass Not Found . 2.在pom.xml文件< ...

  5. Hadoop异常处理 Bad connect ack with firstBadLink (No route to host )

    [root@Node1 ~]# hdfs dfs -put /home/test.txt /lab/input15/04/15 17:29:44 INFO hdfs.DFSClient: Except ...

  6. “大数据讲师”、“Hadoop讲师”、“Spark讲师”、“云计算讲师”、“Android讲师”

    王家林简介 Spark亚太研究院院长和首席专家,中国目前唯一的移动互联网和云计算大数据集大成者. 在Spark.Hadoop.Android等方面有丰富的源码.实务和性能优化经验.彻底研究了Spark ...

  7. MongoVUE 如何导出数据

    1.MongoVUE导出数据 正常连接如数据后,打开对应数据库的collections,然后点击右上角的“Refresh”的下拉小三角,打开export 根据个人喜好,或业务需求,选择导出的格式 最后 ...

  8. linux 命令 之chomd

    chmod用于改变文件或目录的访问权限.用户用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法.  1. 文字设定法 语法:chmo ...

  9. gulp之静态资源防缓存处理

    最近,因为校友网项目开始有些规模了.开始就要考虑对静态资源进行工程自动化的管理.一讲到前端的自动化工具,大家或许都会想到Grunt,Gulp,或者百度的FIS.这三个都有各自的特点,大家可以依据自己的 ...

  10. 汇总:Linux下svn命令大全

    svn(subversion)是近年来崛起的版本管理工具,svn服务器有2种运行方式:独立服务器和借助apache.2种方式各有利弊.不管是那种方式,都需要使用各种命令来实现.在本文中,haohtml ...