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

和上一题一样用个stack就好了

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
using namespace std;
const double pi=acos(-1.0);
stack<int>v;
int a[1005];
bool judge(int n)
{
while(!v.empty()) v.pop();
int ans=1;
rep(i,0,n)
{
while(1)
{
if(v.empty())
v.push(ans++);
if(v.top()==a[i])
{ v.pop();break; }
else
{
if(ans>n)
return false;
else
v.push(ans++);
}
}
}
return true;
}
int main()
{
int n;
while(1)
{
sf("%d",&n);
if(!n) return 0;
while(1)
{
sf("%d",&a[0]);
if(!a[0]) break;
rep(i,1,n) sf("%d",&a[i]);
if(judge(n)) pf("Yes\n");
else pf("No\n");
}
pf("\n");
}
}

F - Rails的更多相关文章

  1. 11月27日 招聘网第七部分,.gitignore的用法。

    回想Rails --Active Record Query Interface--Scopes的基本用法: 1.Passing in arguments.例子:scope  :name , -> ...

  2. Mysql_以案例为基准之查询

    查询数据操作

  3. rails中的form_for

    1 form_for方法是ActionView::Helpers::FormHelper模块内的方法,所以可以在ActionView的实例中直接调用 2 from_for方法的原型为form_for( ...

  4. rails

    http://ruby-toolbox.com/ ~/.gemrc --- :backtrace: false :benchmark: false :bulk_threshold: 1000 :sou ...

  5. rails enum用于存储数据

    http://api.rubyonrails.org/classes/ActiveRecord/Enum.html 新的项目中有一个字段是展示类型,可以用下拉框去做,用string存储具体的类型字段. ...

  6. win764位Ruby2.0环境搭建之Ruby on Rails

    一:安装Ruby 1.在http://rubyinstaller.org 下载需要的ruby版本,因为是exe文件,所以,你可以直接安装. 安装结束后,cmd上运行 ruby -v 显示版本号.如果正 ...

  7. rails使用bootstrap3-wysiwyg可视化编辑器并实现自定义图片上传插入功能

    之前在rails开发中使用了ckeditor作为可视化编辑器,不过感觉ckeditor过于庞大,有很多不需要的功能,而且图片上传功能不好控制不同用户可以互相删除图片,感觉很不好.于是考虑更改可视化编辑 ...

  8. Rails :布局和视图渲染

    原文地址: http://guides.ruby-china.org/layouts_and_rendering.html Rails 布局和视图渲染 本文介绍 Action Controller 和 ...

  9. [ruby on rails] 跟我学之(10)数据输入验证

    这里简单加上几个验证,非空,最小长度,唯一 修改模型 修改app/models/post.rb文件,如下: class Post < ActiveRecord::Base #attr_acces ...

随机推荐

  1. MDX Cookbook 02 - 除数为零的问题

    先直接看一个例子 - WITH MEMBER [Date].[Calendar Year].[CY 2006 vs 2005 Bad] AS ], FORMAT_STRING = 'Percent' ...

  2. Gradle Build Tool

    转自知乎: nonesuccess 通俗的说:gradle是打包用的. 你觉得解决你的问题了吗?如果没解决,那是你的问题提得不够好.比如我猜你应该提:为什么要打包发布,打包发布有几种常见方法,为什么这 ...

  3. <转>vmp3.0.9全保护拆分解析

    以下为了避免插件干扰,故采用x64dbg原版进行分析. 首先我通过检测到调试器的弹窗进行栈回溯,定位到该关键点:CALL eax   由于才接触Vmp,所以是把各个保护拆分开来进行的分析,会比较简单一 ...

  4. 安装babel遇到的异常

    Error: Requires Babel "^7.0.0-0", but was loaded with "6.26.3". If you are sure ...

  5. Ubuntu 下搭建 Android 开发环境(图文)

    转自 http://dawndiy.com/archives/153/ 1.安装JDK 1.下载JDK 目前最新的JDK版本是:Java SE Development Kit 7u5 下载地址: 查看 ...

  6. C++11中的右值引用及move语义编程

    C++0x中加入了右值引用,和move函数.右值引用出现之前我们只能用const引用来关联临时对象(右值)(造孽的VS可以用非const引用关联临时对象,请忽略VS),所以我们不能修临时对象的内容,右 ...

  7. Innotop的安装和使用

    功能特点1.显示当前innodb的全部事务列表:2.显示当前正运行着的查询:3.显示当前锁和锁等等的列表:4.服务器状态和变量的摘要信息 显示了数值的相对变化幅度:5.有多种模式可用来显示Innodb ...

  8. EasyUI - DataGrid 去右边空白滚动条列

    在网上查了很长时间没有找到解决方法,干脆自已查看一下代码来解决吧,随是压缩过的,不过也还是好查的,工夫不负有心人,终于解决了,方法如下: 一.我们先让表格自适应宽度 <!DOCTYPE html ...

  9. 入门:移动APP中的各种导航

    即使是移动应用界面的原型设计,导航的形式也可以多种多样.尽管尺寸小,又必须紧凑排列大量数据,它们似乎受到了紧密的约束,但依然有着形形色色的选择. 人们曾经一度只会考虑一种形式——流行且广泛使用的垂直导 ...

  10. Atitit 数据库view视图使用推荐规范与最佳实践与方法

    Atitit 数据库view视图使用推荐规范与最佳实践与方法 1. 视图的优点:1 1.1. **提升可读性  定制用户数据,聚焦特定的数据1 1.2. 使用视图,可以简化数据操作.       1 ...