POJ1363:Rails
Description
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 last block consists of just one line containing 0.
Output
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的更多相关文章
- 杂项-frame:Rails框架
ylbtech-杂项-frame:Rails框架 Rails框架首次提出是在2004年7月,它的研发者是26岁的丹麦人David Heinemeier Hansson.不同于已有复杂的Web 开发框架 ...
- [Ruby on Rails系列]4、专题:Rails应用的国际化[i18n]
1. 什么是internationalization(i18n)? 国际化,英文简称i18n,按照维基百科的定义:国际化是指在设计软件,将软件与特定语言及地区脱钩的过程.当软件被移植到不同的语言及地区 ...
- ✅问题:Rails.ajax的data不支持{}hash格式。必须使用string。 dataType的格式。
Rails.ajax({ url: url, type: "PATCH", data: {"post":{"category_id":thi ...
- ✅问题:Rails.ajax自定义请求
chatroom.coffee中的js代码: document.addEventListener 'turbolinks:load', -> document.getElementById(&q ...
- Rails:rails链接多个数据库【转】
之前查到Rails应用中连接多个数据库的方式如下: class Cookie < ActiveRecord::Base establish_connection :typo ... end 这样 ...
- Rails:Rails使用sqlite3数据库 及数据操作基本命令
Rails默认使用sqlite3做为数据库,虽然很多人更喜欢mysql.但如果是学习用,sqlite3够了,因为它轻量,不需要安装. 首先对sqlite3做个简短的介绍:1.sqlite3不需要配置, ...
- 栈经典列题:Rails
解题心得: 1.这题是先进后出的顺序,所以使用栈(先进后出表). 2.搞清楚题意,需要达成的序列和进入的序.不要弄混了. 3.思维混乱的时候要冷静,冷静,冷静~~~~! 题目: Description ...
- Windows下: RubyMine + Ruby On Rails + mysql 搭建开发环境
最近在接手一个手机项目.在搭建环境的过程中,遇到了一些问题,在下文中已做记录,并奉上个人的解决方案. 开发环境 win2003 ; JetBrains RubyMine6.3.3 1. 下载最新版 ...
- Rails: No such file or directory - getcwd
这个的意思就是你从一个删除的目录里面运行实例:rails s
随机推荐
- 迁移到gitbook
现在要迁移到gitbook啦, 一些note类分享就只在gitbook发了, 其他一些比较长的分享会第一时间发到gitbook,但也会在这边同步 我的gitbook
- 数据库合并数据sql
1.sql2000中只能用自定义的函数解决 )) , 'aa') , 'bb') , 'aaa') , 'bbb') , 'ccc') go )) ) as begin ) select @str = ...
- Oracle EBS-SQL (SYS-18):检查系统安装的各个表是否打开(PJM%).sql
select status, trigger_name from all_triggers where trigger_name like 'PJM%'; ALTER TRIGGER PJM_ORG_ ...
- 点击按钮改变标签内容(采用lambda函数方式)
from Tkinter import* window=Tk() counter=IntVar() counter.set(0) def click(variable,value): variable ...
- 织梦DEDECMS 首页列表页内容也时间日期调用标签
DEDECMS利用strftime()函数格式化时间的所有参数详解,包括年份日期进制.小时格式等,大家收藏吧,呵. 日期时间格式 (利用strftime()函数格式化时间)0 dedecms首页时间标 ...
- mongoose的populate的使用方法;
LotteryReceiveRecord.find({"lottery":req.params.id}).populate("user lottery").ex ...
- 文档onload处理程序
//第一种方式是注册onload事件处理代码, //onload事件会在页面或图像加载完成后立即发生.这意味着onload事件的执行时间是在 //document对象和document对象所关联的所有 ...
- gridview中使用href调用javascript
传递参数(多个)可用以下两种方法: 方法一: <asp:TemplateField HeaderText="列名1"> <ItemTemplate> < ...
- Html5 自定义数据属性
html5 可以为元素添加自定义属性,但是要添加前缀data-.(下面这个例子中的自定义属性的命名,其实是不规范的,不应该包含大写字符,例如:data-myName 应改命名为:data-myname ...
- java 中有几种方法可以实现一个线程? 用什么关键字修 饰同步方法? stop()和 suspend()方法为何不推荐使用?
java5 以前, 有如下两种:第一种:new Thread(){}.start();这表示调用 Thread 子类对象的 run 方法, new Thread(){}表示一个Thread 的匿名子类 ...