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. Scala写排序可以说是简洁又明了

    例如归并排序,清晰明了. object MergeSort extends App {     val oldList = List[Int](12, 40, 26, 89, 75, 44, 32,  ...

  2. log实例

    配置详解见2014.10月篇 log4j的pom.xml <dependency> <groupId>log4j</groupId> <artifactId& ...

  3. (C)学生成绩管理系统

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h&g ...

  4. ThinkPHP中使用ajax接收json数据的方法

    本文实例讲述了ThinkPHP中使用ajax接收json数据的方法.分享给大家供大家参考.具体分析如下: 这里通过ThinkPHP+jquery实现ajax,扩展了下,写了个查询,前台代码如下: 首先 ...

  5. 《我是一只IT小小鸟》 读后感

    <我是一只IT小小鸟>一只是我想读list中一个本,但是上次去当当买的时候,竟然缺货了...昨天监考,实在无聊,就上网看电子书了,一天就看完了,看得有点仓促,所以理解估计不深. 1.刘帅: ...

  6. Coursera机器学习课程(2016 )错题集

    Unit 4 Neural Networks (×) 分析:估计D项错误,因为神经网络在处理逻辑运算的时候是range(0,1),但是处理别的运算的时候就不是这个范围了 (√) (对) week 6 ...

  7. kvm中运行kvm

    如何在 KVM 虚拟机上运行 KVM 上次讨论了如何在 VMware ESXi 虚拟机上运行 KVM 问题,前不久有读者想 “在 kvm 上面创建个虚拟机安装 rackspace 的 openstac ...

  8. IOS深入学习(3)之Control Object

    1 前言 今天我们来简单的学习一下IOS中用户点击屏幕后的事件处理,其中主要介绍一下Control Object,内容如下. 2 详述 Control是处于当用户用某种方式操作进行发送消息给另一个界面 ...

  9. 菜鸟级SQL Server21天自学通(文档+视频)

    SQL语言的主要功能就是同各种数据库建立联系,进行沟通.按照ANSI(美国国家标准协会)的规定,SQL被作为关系型数据库管理系统的标准语言.SQL语句可以用来执行各种各样的操作,例如更新数据库中的数据 ...

  10. k8s之scheduler

    一.概述 调度器是kubernetes中独特而又重要的一个模块,独特是因为scheduler是唯一一个以plugin形式存在的组件,重要是因为kubernetes中最重要的基础单元pod的部署是通过s ...