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
随机推荐
- Python环境变量配置问题
安装Python2.7后,在环境变量中加入路径方法如下: 1,设置:右键单击计算机-->属性-->高级系统设置-->环境变量-->Path-->编辑Path-->在 ...
- linux select函数 shutdown函数
#include<sys/select.h> #include<sys/time.h> int select(int maxfdp1,fd_set *readset,fd_se ...
- OSG报警特效学习总结
方法一:粒子系统 OSG的粒子系统有自己定义好的模块,如osgParticle::ExplosionEffect(爆炸模拟):osgParticle::SmokeEffect(烟雾模拟 ...
- 如何解决”无法将类型为“System.DateTime”的对象强制转换为类型“System.String”。“
字段Time在数据库中为datetime类型 dr.GetString(3).ToString() dr.GetString(3).ToString() => dr.GetDateTime(3) ...
- Java pipeline
http://cullenprogramming.homelinux.com/PIPEuserguide.htm http://www.cise.ufl.edu/research/ParallelPa ...
- cdoj 斐波那契进制
//昨天在姜神的提醒下发现这种方法可以解决升级版的 非升级版直接01背包就好 //这题脑洞开得真是够大 解:大概要先把数分解成斐波拉契进制,x=f1*(0或1)+f2*(0或1)+...+fn*(0或 ...
- Android牛博
Android实现伸缩弹力分布菜单效果 摘要: 本文介绍下在Android中实现伸缩弹力分布菜单效果.关于这种菜单效果在IPhone中比较常见,效果比较酷.那么在Android中实现只是一种简单的模仿 ...
- css两个紧挨着的css选择器修饰同一个元素
#status, .commands{ height: 25px; line-height: 25px;}.upload .commands{ float: right;}.hidden{ displ ...
- NGINX 多个域名配置
多个域名配置: 依赖于 include 这个功能会加在 这2个文件夹下的所有配置文件. 所以我们可以配置多个 conf 放置于这些文件夹中.这样就是先了多个域名配置 conf 内容大致如下 s ...
- 性能优化工具---vmstat
作用: 报告关于内核线程.虚拟内存.磁盘.陷阱和 CPU 活动的统计信息 参数: 通过两个数字参数来完成的,第一个参数是采样的时间间隔数,单位是秒,第二个参数是采样的次数 显示说明: 第一行数据反映开 ...