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 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.

Input

The input consists of blocks of lines. Each block except the last describes one train and possibly more requirements for its reorganization. In the first line of the block there is the integer N described above. In each of the next lines of the block there is a permutation of 1, 2, ..., N. The last line of the block contains just 0.

The last block consists of just one line containing 0.

Output

The output contains the lines corresponding to the lines with permutations in the input. A line of the output contains Yes if it is possible to marshal the coaches in the order required on the corresponding line of the input. Otherwise it contains No. In addition, there is one empty line after the lines corresponding to one block of the input. There is no line in the output corresponding to the last ``null'' block of the input.

Sample Input

5
1 2 3 4 5
5 4 1 2 3
0
6
6 5 4 3 2 1
0
0

Sample Output

Yes
No Yes
 
题意:按1~n进栈,然后给出一个顺序,看能否按照这个顺序出栈
 
#include<stdio.h>

int main()
{
int a[1005],b[1005],i,j,k,n;
while(scanf("%d",&n),n)
{
while(scanf("%d",&b[0]),b[0])
{
for(j=1; j<n; j++)
scanf("%d",&b[j]);
for(i=1,j=0,k=0; i<=n&&j<n; i++,k++)
{
a[k]=i;
while(a[k]==b[j])
{
if(k>0)k--;
else
{
a[k]=0,k--;
}
j++;
if(k==-1)break;
}
}
if(j==n)printf("Yes\n");
else printf("No\n");
}
printf("\n");
}
}

POJ1363:Rails的更多相关文章

  1. 杂项-frame:Rails框架

    ylbtech-杂项-frame:Rails框架 Rails框架首次提出是在2004年7月,它的研发者是26岁的丹麦人David Heinemeier Hansson.不同于已有复杂的Web 开发框架 ...

  2. [Ruby on Rails系列]4、专题:Rails应用的国际化[i18n]

    1. 什么是internationalization(i18n)? 国际化,英文简称i18n,按照维基百科的定义:国际化是指在设计软件,将软件与特定语言及地区脱钩的过程.当软件被移植到不同的语言及地区 ...

  3. ✅问题:Rails.ajax的data不支持{}hash格式。必须使用string。 dataType的格式。

    Rails.ajax({ url: url, type: "PATCH", data: {"post":{"category_id":thi ...

  4. ✅问题:Rails.ajax自定义请求

    chatroom.coffee中的js代码: document.addEventListener 'turbolinks:load', -> document.getElementById(&q ...

  5. Rails:rails链接多个数据库【转】

    之前查到Rails应用中连接多个数据库的方式如下: class Cookie < ActiveRecord::Base establish_connection :typo ... end 这样 ...

  6. Rails:Rails使用sqlite3数据库 及数据操作基本命令

    Rails默认使用sqlite3做为数据库,虽然很多人更喜欢mysql.但如果是学习用,sqlite3够了,因为它轻量,不需要安装. 首先对sqlite3做个简短的介绍:1.sqlite3不需要配置, ...

  7. 栈经典列题:Rails

    解题心得: 1.这题是先进后出的顺序,所以使用栈(先进后出表). 2.搞清楚题意,需要达成的序列和进入的序.不要弄混了. 3.思维混乱的时候要冷静,冷静,冷静~~~~! 题目: Description ...

  8. Windows下: RubyMine + Ruby On Rails + mysql 搭建开发环境

    最近在接手一个手机项目.在搭建环境的过程中,遇到了一些问题,在下文中已做记录,并奉上个人的解决方案. 开发环境 win2003 ;  JetBrains RubyMine6.3.3 1.  下载最新版 ...

  9. Rails: No such file or directory - getcwd

    这个的意思就是你从一个删除的目录里面运行实例:rails s

随机推荐

  1. 剑指offer——已知二叉树的先序和中序排列,重构二叉树

    这是剑指offer中关于二叉树重构的一道题.题目原型为: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和中序遍历的结果中都不含重复的数字.例如输入前序遍历序列{1,2, ...

  2. Mirror–使用证书配置镜像模板

    –==================================================================–该文档主要用于内部配置模板–场景:–主服务器:192.168.3 ...

  3. linux下各种代理的设置

    http://los-vmm.sc.intel.com/wiki/OpenStack_New_Hire_Guide#Apply_JIRA_account Set up your proxy. The ...

  4. 关于微信的jsapi_ticket的获取方法;

    对于一个从前端转到后端的开发人员来说,这个玩意儿开始的时候是有点郁闷:不过明白原理之后就简单了, 获取jsapi_ticket:必须先获取access_token; 微信开发文档说access_tok ...

  5. lodash的中文文档(不全)

    http://dingliang-321.iteye.com/blog/2184747

  6. 数学之路-python计算实战(13)-机器视觉-图像增强

    指数变换的基本表达式为:y=bc(x-a)-1 当中參数b.c控制曲线的变换形状,參数a控制曲线的位置. 指数变换的作用是扩展图像的高灰度级.压缩低灰度级.能够用于亮度过高的图像 本博客全部内容是原创 ...

  7. xcode - 移动手势

    #import "ViewController.h" @interface ViewController () /** 创建一个UIView */ @property(nonato ...

  8. 虚拟键盘,移动web开发的痛

    原生APP的弹出虚拟键盘和收回虚拟键盘,输入框始终贴在虚拟键盘的上方.如下图: 如果移动端web也想做类似的功能,可以实现吗?  你可能会说着:“不就是放一个position: fixed;的输入框在 ...

  9. Ext.Net 使用总结之GridPanel的删除事件

    1.关于Ext.net中GridPanel的删除事件 首先是GridPanel,如下: <ext:GridPanel ID="GridPanel1" runat=" ...

  10. 通过git和Xcode将代码上传到GitHub

    长话短说: 第一步:初始化一个本地仓库 git init 第二步:将你的文件添加到缓存区 git add . 后面的空格 . 是将全部的文件都添加到缓存区  可以使用git status  查看状态 ...