NOJ1098Rails——出栈顺序

POJ 1363 Rails (值得一记的栈好题) Rails Time Limit: 1000MS Memory Limit: 10000K 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 possibl 阅读详情

Rails

时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte
总提交:370            测试通过:111

描述

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 coaches numbered in increasing order . 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 . 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.

输入

The input file 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 The last line of the block contains just 0. 
The last block consists of just one line containing 0. 

输出

The output file contains the lines corresponding to the lines with permutations in the input file. A line of the output file contains Yes if it is possible to marshal the coaches in the order required on the corresponding line of the input file. Otherwise it contains No. In addition, there is one empty line after the lines corresponding to one block of the input file. There is no line in the output file corresponding to the last ``null'' block of the input file.

样例输入

5
1 2 3 4 5
5 4 1 2 3
0
6
6 5 4 3 2 1
0
0

样例输出

Yes
No

Yes

题目来源

Central European Regional 1997


分析:C++数据结构中很重要的题目。这里亲自写,感受不同了~

考验出栈顺序是否可行。自己写数组较快。内部判断条件。注意 j 的限制条件必须加上,因为 i 会变小。

//Rails——出栈顺序
#include<stdio.h>

int main()
{
	int a[1000], input[1000];
	int n;
	while(scanf("%d",&n) && n != 0)
	{
		while(scanf("%d",&input[0]) && input[0]) // 0
		{
			for(int i=1;i<n;i++) scanf("%d",&input[i]);
			int num = 0; // input匹配个数
			for(int i=0,j=1;i<n&&j<=n;i++,j++) // j<=n!!!因为i减小了,必须加上j的限制条件
			{
				a[i] = j;
				while(a[i] == input[num])
				{
					num++;
					i--;
					if(i == -1) break;
				}
			}
			if(num == n) printf("Yes\n");
			else printf("No\n");
		}
		printf("\n");
	}

	return 0;
}


Uva514-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 e 阅读详情

相关推荐

实验二——栈和队列的基本操作及应用

实验内容和要求 [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 ti...

DEAR_CXN的博客 1730

【每日一题】poj 1363: 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 tu

Josvin 1508

hdu 4252 #想法

A Famous City Time Limit: 10000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 119    Accepted Submission(s): 64 Problem Description After Mr. B ar

Mr.CJ 1059

Rails题解C++STL实现

There is a famous railway station in PopPush City. Country there is incredibly hilly. The stationwas built in last century. Unfortunately, funds were extremely limited that time. It was possible toestablish only a surface track. Moreover, it turned out th.

qq_51955445的博客 1512

从硅片到时钟:揭秘SiTime MEMS谐振子的精密制造之旅

本文深入解析了SiTime MEMS谐振子的精密制造工艺,从硅晶圆的提纯到DRIE深硅刻蚀,再到真空封装技术,揭示了其如何克服传统石英晶振的局限。通过对比测试数据,展示了MEMS谐振子在精度、可靠性和生产效率上的显著优势,特别是在5G基站和汽车电子等领域的应用潜力。

weixin_42522953的博客 402

李宏毅机器学习笔记第17周_概述领域自适应(Domain Adaptation)

Domain Adaptation

peaunt1的博客 1104

不可能的出栈顺序

每一个出栈的元素的后面,其中比该元素先入栈的一定按照入栈逆顺序排列。 入栈A,B,C,D,E,若第一个出栈的是D,在D之前入栈的有A、B、C,则后续ABC的出栈顺序只能为C,B,A。

葭月廿四的博客 2700

FC游戏Hack实战:从零开始修改游戏数据

本文以《忍者神龟3》为例,详细介绍了从零开始进行FC游戏Hack的完整实战流程。通过使用FCEUX模拟器和调试器,结合“递减法”精准定位生命值内存地址,并利用十六进制编辑器修改关键指令,最终实现“无限生命”效果。文章旨在引导读者理解游戏数据修改的核心原理与操作技巧,重温经典的同时深入计算机程序运行机制。

weixin_28366353的博客 356

Rails

FJNU.1221DescriptionThere 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

linyq@BambooFan ~ 729

RK3399平台开发系列讲解(外设篇)交换芯片RTL8306M

网络:交换芯片RTL8306M 电路: make menuconfig 配置: 目录:arch/arm64/configs/rk3399_b201_defconfig CONFIG_FIXED_PHY=y 设备树: arch/arm64/boot/dts/rockchip/rk3399-b201-rev1.dts 时钟: Open之后首先校验网卡mac地址是否正确(stmmac_chec...

内核笔记 2390

PLSQL Developer安装详细步骤

一、下载安装PLSQL Developer(plsql安装百度也有步骤) 官网下载地址:https://www.allroundautomations.com/registered-plsqldev/ 1、网上自己下载适合自己电脑的安装包(32或64),并解压。 2、打开解压的文件夹,得到以下三个文件(分别是汉化工具,PLSQL安装包、激活码),双击安装,如下图: 3、安装界面,点击next,进入下一步,如图: 4、安装协议界面,此处必须选择“I accept the terms in

Gorden的博客 11万+

There is a famous railway station in PopPush City. Country there is incredibly hil

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 .

with_wine的博客 918

海康VisionMaster与西门子Smart 200进行S7通信

海康VisionMaster与西门子Smart 200进行S7通信

haier123888的博客 8177

Rails(判断出栈顺序是否合理)

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

越努力,越幸运!!! 883

笔试题-2023-加特兰-数字IC设计【纯净题目版】

笔试题-2023-加特兰-数字IC设计【纯净题目版】

w0shishabi的博客 2248

python中使用squarify包可视化treemap图:为treemap图添加标题并自定义标题的字体大小、自定义设置treemap中标签字体的大小、添加数值数值标签、自定义设置边框的色彩

python中使用squarify包可视化treemap图:treemap将分层数据显示为一组嵌套矩形自定义设置每一个数据格的颜色、添加数值数值标签、自定义设置边框的色彩、自定义设置边框线条的粗细、为treemap图添加标题并自定义标题的字体大小、自定义设置treemap中标签字体的大小

data+scenario+science+insight 1061

NOJ 2024 入栈序列和出栈序列 (stack)

入栈序列和出栈序列 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte 总提交:205            测试通过:50 描述 给出入栈序列{A},保证{A}各个元素值各不相等,输出字典序最大的出栈序列. 如入栈序列{A} = 1, 2, 9, 4, 6, 5 则字典序最大的出栈序列为9, 6, 5, 4, 2,

Tc的专栏 1339

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

UVA_Rails

UVA 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

Sothan 602

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

poj 1363 Rails (栈的应用+STL)

Rails Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24762   Accepted: 9715 Description There is a famous railway station in PopPush City. Country there is

Just do it ! 3352

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

一个栈的入栈序列为ABCDEF,则不可能的出栈序列是

技术之瞳 阿里巴巴技术笔试心得习题2.65:   一个栈的入栈序列为ABCDEF,则不可能的出站序列是(D)   A、DEFCBA    B、DCEFBA    C、FEDCBA   D、FECDBA    E、ABCDEF    F、ADCBFE

无鞋童鞋的博客 3万+

出栈次序

标题:出栈次序    X星球特别讲究秩序,所有道路都是单行线。 一个甲壳虫车队,共16辆车,按照编号先后发车,夹在其它车流中,缓缓前行。    路边有个死胡同,只能容一辆车通过,是临时的检查站,如图【p1.png】所示。    X星球太死板,要求每辆路过的车必须进入检查站,也可能不检查就放行,也可能仔细检查。    如果车辆进入检查站和离开的次序可以任意交错。那么,该车队再次上路后,可能的次序有多...

qq_38648587的博客 1595

(stack)Rails(P1363)

#include #include #include using namespace std; int go[1000000]; int main() { int i,j,k; int n; while (cin>>n,n) { while (true) { cin>>go[0]; if (go[0]==0) break; for (i=1;i<n

jiangjiashi的博客 907

poj 1363 Rails in PopPush City &&【求堆栈中合法出栈顺序次数】

问题如下: 问题 B: Rails 时间限制: 1 Sec 内存限制: 64 MB 提交: 14 解决: 4 [提交][状态][讨论版] 题目描述 There is a famous railway station in PopPush City. Country there is incredibly hilly. The station was built in...

weixin_30887919的博客 359

UVa 514 - Rails 注意最后的输出

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

GodLike 1791
上一篇: NOJ1097卡片游戏——queue
下一篇: NOJ1099移动小球——经典的想法
tcherry
博客等级 码龄16年 46粉丝 161原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值