F - Rails
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的更多相关文章
- 11月27日 招聘网第七部分,.gitignore的用法。
回想Rails --Active Record Query Interface--Scopes的基本用法: 1.Passing in arguments.例子:scope :name , -> ...
- Mysql_以案例为基准之查询
查询数据操作
- rails中的form_for
1 form_for方法是ActionView::Helpers::FormHelper模块内的方法,所以可以在ActionView的实例中直接调用 2 from_for方法的原型为form_for( ...
- rails
http://ruby-toolbox.com/ ~/.gemrc --- :backtrace: false :benchmark: false :bulk_threshold: 1000 :sou ...
- rails enum用于存储数据
http://api.rubyonrails.org/classes/ActiveRecord/Enum.html 新的项目中有一个字段是展示类型,可以用下拉框去做,用string存储具体的类型字段. ...
- win764位Ruby2.0环境搭建之Ruby on Rails
一:安装Ruby 1.在http://rubyinstaller.org 下载需要的ruby版本,因为是exe文件,所以,你可以直接安装. 安装结束后,cmd上运行 ruby -v 显示版本号.如果正 ...
- rails使用bootstrap3-wysiwyg可视化编辑器并实现自定义图片上传插入功能
之前在rails开发中使用了ckeditor作为可视化编辑器,不过感觉ckeditor过于庞大,有很多不需要的功能,而且图片上传功能不好控制不同用户可以互相删除图片,感觉很不好.于是考虑更改可视化编辑 ...
- Rails :布局和视图渲染
原文地址: http://guides.ruby-china.org/layouts_and_rendering.html Rails 布局和视图渲染 本文介绍 Action Controller 和 ...
- [ruby on rails] 跟我学之(10)数据输入验证
这里简单加上几个验证,非空,最小长度,唯一 修改模型 修改app/models/post.rb文件,如下: class Post < ActiveRecord::Base #attr_acces ...
随机推荐
- .NET 用 Unity 依赖注入——概述注册和解析类型(1)
本文内容 Unity 概述 环境 一个真实的例子 类型注册(Type Registrations) 解析类型(Resolving Types) 跳槽,新公司使用了 Unity,初步看了一下,公司的使用 ...
- Hbase 命令小结
1.创建test,如果存在先删除 hbase(main)::> disable 'test' row(s) in 1.4250 seconds hbase(main)::> drop 't ...
- redis 基本信息查询
在客户端可以用telnet命令 telnet ip port 再输入info 返回如下信息:
- 基于Python使用Redis的一些想法和建议
目录 1关于Redis使用的一点想法 1.1进行缓存前,需考虑 1.2进行缓存后,需考虑 1.3缓存使用一段时间后 2编写Redis数据库层规范建议 2.1选择适合的redis客户端 2.2规范化定义 ...
- Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed
在使用SpringMVC绑定基本类型(如String,Integer等)参数时,应通过@RequestParam注解指定具体的参数名称,否则,当源代码在非debug模式下编译后,运行时会引发Handl ...
- CentOS6.9下安装python notebook
操作系统:CentOS6.9_x64 python版本 : python2.7.13 添加低权限新用户: useradd mike su mike 使用virtualenv安装python2.7环境 ...
- TinyMCE与Domino集成
TinyMCE与Domino集成 一:TinyMCE简介 TinyMCE是一个轻量级的基于浏览器的所见即所得编辑器,由JavaScript写成.它对IE6+和Firefox1.5+都有着非常良好的支持 ...
- (原)ubuntu中使用conda安装tensorflow-gpu
转载请注明出处: https://www.cnblogs.com/darkknightzh/p/9834567.html 参考网址: https://www.anaconda.com/blog/dev ...
- 解决 Firefox 下载文件名乱码扩展 ReDisposition
作者 muzuiget 发布 2013-03-13 19:23 标签 redisposition Firefox 下载文件名乱码问题由来已久,偶然一两次还可以手动改名,批量下载时简直要亲命,最终我 ...
- MySQL数据切分的相关概念和原理详解
对于数据切分,我们可能还不是很熟悉,但是它对于MySQL数据库来说也是相当重要的一门技术,本文我们就详细介绍一下MySQL数据库的数据切分的相关知识,接下来就让我们一起来了解一下这部分内容. 什么是数 ...