POJ1363

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

\POJ1363](http://poj.org/problem?id=1363)


这里写图片描述


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 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

Source

Central Europe 1997

题意:

模拟栈操作。已知入栈顺序1..N,问可否按照给出的顺序出栈。练习stack的入门……
按照顺序入栈,随时按照标准出栈,看最后是否栈空即可。
注意格式莫PE

code:

#include <stack>
#include <cstdio>
using namespace std;
typedef long long LL;
const int mx = 1010;
int n,a[mx],i;
bool nfi;
int main() {
    while (~scanf("%d",&n)&&n) {
        if (nfi) printf("\n");
        while (~scanf("%d",&a[1])&&a[1]) {
            for (i=2; i<=n; ++i)
                scanf("%d",&a[i]);
            stack<int> S;
            i=1;
            for (int j=1; j<=n; ++j) {
                S.push(j);
                while (!S.empty()&&S.top()==a[i]) {
                    S.pop();
                    i++;
                }
            }
            if (S.empty()) printf("Yes\n");
            else printf("No\n");
        }
        nfi=true;
    }
    return 0;
}

ps:Markdown小试

POJ1363 Rails中英文对照翻译与参考解答 阅读详情

相关推荐

【 POJ 1363 】Rails

一道把我坑了的简单水题。 不知道为什么深究了,而且弄不清,一直到凌晨,现在北京时间1.14——留作纪念。其实那个先对比还是挺巧妙地。 如果a和b[]不等的话,压栈,相等的话再看栈是不是为空,不空则弹栈,如果空的话直接进入下个比较。 不多说,下面都有注释。 ————————————————————————————————————————题目:RailsRailsTime Limit: 1000

Nodies 455

POJ 1363 Rails 模拟栈

来源:http://poj.org/problem?id=1363 题意:有一列火车,车厢编号为1到n,只能由一段进站,另一端出站。现在进站顺序确定,给出一个出站的顺序,判断出站顺序是否可能。 思路:其实就是一个模拟栈的过程,先进后出。但是由于会出现这样的情况,比如说:1 2 3进栈,然后3出栈,然后4 5进栈,所以该出栈的顺序是3 5 4 2 1,所以在模拟的过程中需要注意一下。 还有就是

2009

pku(poj)--2494--Acid Text--java代码

用Java代码实现POJ(PKU)上题2494!

POJ1363 Rails【单调栈】

附上原题链接:http://vjudge.net/problem/POJ-1363 题意:已知火车要从A站入站,再从C站出站,最后才从B站出。即A->C,C->B。 分析:此题直接模拟栈即可。把C站看做是一个栈,然后火车的车厢按顺序入栈,如果栈顶的火车编号与出站的火车编号一样,那么就出栈,直到栈里边所有满足出站顺序的火车都出站,否则就一直入栈。最后判断火车是否都出站了,如果都出站了就输出Yes

从前从前有个人爱你很久 353

数字IC物理验证实战 | 从Calibre LVS报告到Innovus定位的Debug全链路解析

本文详细解析了数字IC物理验证中Calibre LVS报告的Debug全流程,从INCORRECT NETS错误的初探到Innovus定位技巧,提供了实战案例和高效工具的使用方法。重点介绍了Calibre高亮功能、Innovus验证命令以及前后端工具联动的关键策略,帮助工程师快速定位和解决LVS问题,提升物理验证效率。

weixin_30919429的博客 127

软考软件评测师备考避坑指南:过来人告诉你这5个章节最容易丢分(附2024最新考纲解析)

本文为软考软件评测师考生提供备考避坑指南,深度解析5个高频失分章节,包括标准化与信息化基础、中间件技术、软件测试模型、白盒测试覆盖准则和性能测试指标。文章结合2024最新考纲,分享实战技巧和记忆口诀,帮助考生精准打击失分重灾区,提升备考效率。

weixin_29223603的博客 467

POJ 1363 Rails 判断出栈序列是否合法

题目链接:http://poj.org/problem?id=1363  (lrj白书习题) 题目大意:判断一个出栈序列能不能从1,2,3,……,n 经过栈处理后生成。 思路: Ⅰ:定理:出栈序列不合法 <=> 存在k,满足i<j<k,使得S[k]<S[i]<S[j]。(i,j,k是入站顺序,s[i],s[j],s[k]是出栈顺序)。 如果用这个定...

weixin_30666753的博客 163

光学设计进阶:Zemax中的坐标断点与离轴系统优化

本文深入解析了Zemax中坐标断点的核心原理与实战应用,它是实现离轴光学系统设计的关键。文章通过比喻和实例,详细阐述了如何利用坐标断点作为“方向盘”来精确控制光学元件的偏心和倾斜,实现“前断后接”的局部坐标系变换,从而构建并优化无中心遮拦的离轴反射系统,避免光线失控。

3a9bq4r8t2y的博客 527

POJ 1363 Rails

POJ 1363 RailsDescription 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

long-long-ago 447

梦幻西游端游脚本开发实战:从易语言到大漠多线程全解析

本文详细解析了梦幻西游端游脚本开发的全流程,从易语言基础入门到大漠插件多线程实战。重点介绍了易语言中文编程优势、大漠插件图色识别技术,以及多线程控制台开发技巧,帮助开发者高效实现游戏自动化,提升脚本稳定性和执行效率。

weixin_29251567的博客 1061

【大语言模型 85】IA3与其他PEFT方法对比

在大语言模型时代,参数高效微调(PEFT)技术成为了降低微调成本的关键。本文深入解析IA3(Infused Adapter by Inhibiting and Amplifying Inner Activations)方法,并与LoRA、AdaLoRA、Prefix Tuning等主流PEFT技术进行全面对比,通过理论分析、代码实现和实验验证,帮助读者理解不同PEFT方法的优劣势和适用场景,为实际项目中的技术选型提供科学依据。

熵数实验室 753

【poj】1363-Rails

#include #include #include const int MAXSIZE = 10000; using namespace std; int trains[MAXSIZE]; int orders[MAXSIZE]; int stacks[MAXSIZE]; int top; int main() { // freopen("b:\\acm\\input.txt","r"

c0de4fun的完美算(nei)法(he)教室-我们仍不知道,那天调用的驱动的名字。 860

QT-Creator安装教程(windows)

本文介绍了Qt的下载安装步骤:1)通过镜像源下载安装包;2)运行exe文件时使用命令行参数指定镜像地址;3)在安装过程中选择路径和自定义安装组件,包含QT5和QT6版本的详细安装说明;4)安装后可继续添加扩展包或卸载组件。重点提示了QT6必须勾选的关键组件,并提供了组件管理的操作方法。

qq_53545309的博客 3108

[poj] 1363 Rails

[poj] 1363 Rails 【题目】http://poj.org/problem?id=1363 【题意】判断是否能通过栈将顺序列转化为相应队列 【算法】栈模拟 【题解】将未进栈的元素直接输出,之前的元素进栈;判断进栈的元素是不是栈顶,若在栈顶则出栈,反之该队列无法得到。 【注意】标记进栈元素所在栈的位置和元素是否进栈。 注意输出格式 【测试】 无 【代码】 #inclu

464

YOLOv11改进 | Conv改进篇 | 含2种改进,引入DynamicConv替换普通Conv卷积下采样和C3k2_DynamicConv替换C3k2(来自CVPR2024)

本文提出了一种基于DynamicConv动态卷积优化的YOLOv11轻量化模型改进方案。通过引入多专家机制的动态卷积模块,在增加模型参数量的同时保持较低的计算复杂度(FLOPs),有效解决了低FLOPs模型在大规模预训练中的性能瓶颈问题。文章详细介绍了动态卷积的工作原理、核心代码实现,并提供了在YOLOv11中集成DynamicConv和C3k2_GhostModule_DynamicConv模块的完整教程,包括模块添加、配置文件修改和模型训练验证过程。实验结果表明,该方案在保持高效推理速度的同时显著提升了

Ai缝合怪、助力小伙伴高效发论文 537

【StreamSet】ETL之StreamSet之Pipelines的状态监听之WebHook钉钉篇

介绍下StreamSets的状态监听以及钉钉的webhook的互联,这位博友问的恰是时候,不久前我刚刚对接过钉钉的机器人,这次看到这个问题,对我来说,应该轻车熟路了,那就有了这篇博文,状态监听之钉钉篇。...

m0_54252387的博客 488

POJ 1363 火车厢排队问题(栈)

题目链接:http://poj.org/problem?id=1363 题目大意: A站有编号为1到N,N最大1000,的车厢,车厢进入中转station了就不能回到A,只能停在station内或者进入B站,问能不能按照给定的顺序排成那样的车厢号。 ...

Michael是个半路程序员 1907

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

poj 1363(Stack ) Rails

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

twobqn123的专栏 792

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

poj 1363

终于考试完了,又可以学习啦! poj1363,这道题是数据结构与算法中的经典问题,给定一组进栈顺序,问栈有多少种出去的顺序,而这个题是选择题中常考“下列出栈顺序中不合法的是?”。 拿到之后最直接的思路就是模拟进出栈,代码AC了,但是时间为94ms。感觉不应该啊,这么简单的题,必定有更高效的算法。 可是怎么更高效呢? /* * ===========================

冰上游鱼 2630

IDEA的使用指南

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

poj 1363 Rails

题目链接:http://poj.org/problem?id=1363 题目大意:1~n输入,然后以题目要求进行输出,判断能否实现!“0”表示一组数据的结束~注意每组输出后有一个空行! 1 #include 2 #include 3 #include 4 using namespace std; 5 int main () 6 { 7 int t,f

若忆_star 462

POJ1363--出栈顺序(栈的应用)

题目:http://poj.org/problem?id=1363 自己写完之后看到网上的做法的确感觉自己的算法很慢也很耗时,但是还是贴一下。题意不多说(当然也是读了很久才看懂),入栈顺序一定1,2,3...N,给你出栈序列,如果能按着出栈序列出栈则输出"Yes",否则输出"No"。 算法: 1.设置三个stack:A,B,buffer。A:N-->1依次入栈,栈顶为1;B:出栈

懂幸福,爱生活 2109

poj1363

http://poj.org/problem?id=1363 通过栈模拟,检验有无可能实现输入和输出 1 #include<stdio.h> 2 int sum; 3 int *in,*out,*stack; 4 int inpoint,outpoint,stackpoint; 5 int is_ok() 6 { 7 inpoint=-1,outpoint=0,...

weixin_30852419的博客 99

POJ 1363 Rails 解题报告

POJ 1363 Rails 解题报告 题目的意思是给出一组数,问你是不是一组合法的出栈序列。 我有两个思路: 1、每个已出栈之后的数且小于此数的数都必须按降序排列。复杂度O(n^2) 2、另一个思路就是直接模拟入栈出栈过程。虽然模拟毫无技巧可言,但复杂度O(n),优于算法1。 1 2#include<cstdio> 3 4intstack[1...

deng530557273的博客 413

POJ1363-Rails

http://poj.org/problem?id=1363 #include<cstdio> #include<stack> using namespace std; int a[1000]; int main(void) { int n; while(scanf("%d",&n),n) { int...

weixin_30685047的博客 195
上一篇: 山东OI2017-数字表格
下一篇: 河南OI2016·食物链
cybbsc
博客等级 码龄10年 15粉丝 87原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值