hdu-1022-Train Problem I

HDU 1022 Train Problem I 附详细思路 立即下载

As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes a problem, there is only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves, train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your task is to determine whether the trains can get out in an order O2. 
  
Input
The input contains several test cases. Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the end of file. More details in the Sample Input. 
Output
The output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway, and "out" for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output. 
Sample Input
3 123 321
3 123 312
Sample Output
Yes.
in
in
in
out
out
out
FINISH
No.
FINISH


        
  
For the first Sample Input, we let train 1 get in, then train 2 and train 3.
So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1.
In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3.
Now we can let train 3 leave.
But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment.
So we output "No.".
Hint
Hint




#include <iostream>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    while(cin>>n  && n)
    {
        getchar();
        char str[15],mod[15];
        scanf("%s%*c%s%*c",str,mod);
        stack<char> st;
        while(!st.empty())
            st.pop();

        int i, j;
        bool step[100];
        int k=0,sum=0;
        for(i=0,j=0 ;i<=n && j<n && sum <= 9 ;i++)
        {
            st.push(str[i]);
            step[k++]=1;
            sum++;
            while(!st.empty() && st.top()==mod[j])
            {
                st.pop();
                step[k++]=0;
                j++;
                sum--;
            }
        }
        if(st.empty()&&( i>n || j>=n ))
        {
            cout<<"Yes."<<endl;
            for(i=0 ; i<k ; i++)
            {
                if(step[i])
                {
                    cout<<"in"<<endl;
                }
                else
                {
                    cout<<"out"<<endl;
                }
            }
            cout<<"FINISH"<<endl;
        }
        else
        {
            cout<<"No."<<endl<<"FINISH"<<endl;
        }
    }
    return 0;
}


Midscene.js(2):代码集成 + 桥接模式(Bridge Mode)的使用「喂饭教程」 本文将手把手教你从零开始搭建一个 Node.js 项目,集成 Midscene.js,并利用其桥接模式实现对 Chrome 浏览器的自动化操作。我们将通过具体的实例,来展示 Midscene.js 的便捷性与 AI 能力的结合。 阅读详情

相关推荐

SolidWorks草图绘制实战:如何用图片参考快速搞定智能小车底板设计

本文详细介绍了在SolidWorks中利用图片参考进行草图绘制的实战方法,以智能小车底板设计为例,帮助设计师快速将概念转化为精准三维模型。通过插入、对齐参考图片并高效描图,结合参数化约束与尺寸驱动,大幅提升设计效率和准确性,尤其适合新手入门与老手优化工作流。

rust6ferris的博客 233

HDU 1022(栈)

Hdu 1022(栈) 问题描述: 随着新学期的到来,如今的伊格纳修斯火车站非常繁忙。许多学生想乘火车回到学校(因为伊格纳修斯火车站的火车是全世界最快的火车)。但是,这里出现了一个问题,所有火车停靠的只有一条铁路。所以所有的火车都是从一侧进来的,而从另一侧出来的。对于此问题,如果火车A先进入铁路,然后火车B在火车A离开之前就进入铁路,那么火车A直到火车B离开后才能离开。下图说明了问题所在。现在的问题是,车站中最多有9列火车,所有火车都有一个ID(从1到n编号),火车以O1的顺序进入铁路,您的任务是确定火

CrazyRabbitttt 574

【Cadence】PSS+PSTB/PAC仿真在开关电源稳定性分析中的关键应用

本文深入探讨了Cadence仿真工具中PSS+PSTB/PAC方法在开关电源稳定性分析中的关键应用。针对开关电源作为时变非线性系统的特性,传统STB仿真方法会失效。文章详细阐述了如何通过PSS分析找到周期稳态,并在此基础上利用PSTB或PAC进行精确的环路增益和小信号频响分析,为电源设计提供可靠的稳定性评估与补偿网络设计依据。

weixin_29276847的博客 549

【STL栈和队列】HDU-1022 Train Problem I

注解 1、栈的应用。 2、队列的应用。 3、STL。 4、具体到本题而言,每次输入一个字符时,与输出队列的队头比较(栈输出的顺序,其实用一个队列表示更好,因为主要操作是取队头),如果相同,则该字符串出栈、出队列。直到把输入字符串读入完成,如果输出队列为空,则表明可以按该顺序出栈。否则,表明不可按该顺序出栈。每次的in和out操作,都记录在一个vector中,如果最后答案是yes,就把vecto...

zhanggirlzhangboy的博客 229

分析国外几款主流蜜罐产品看欺骗诱捕技术的应用脉络

网络安全的本质是攻防对抗,更本质的其实是人与人心智与技术的全面较量。 欺骗诱捕技术作为攻防对抗技术中比较特殊的技术,能够使防守方更多掌握对抗中的主动权,诱导攻击,迫使攻击者耗费精力的同时,留下丰富的攻击信息。究其本质,欺骗诱捕技术更深层次考验的不止是技术的能力,还有对于攻击者作为人的理解。 国外主流蜜罐产品分析 根据MarketsandMarkets《欺骗技术市场规模、份额和2021年全球市场预测》中提到的欺骗诱捕技术全球主要供应商及产品,我们分析了几款国外主流的蜜罐产品,希望更清晰看到欺骗诱捕技术应

cdyunaq的博客 1331

PRD撰写效率翻倍秘籍:我是如何用大模型+飞书文档搭建自动化工作流的

本文分享了如何利用大模型与飞书文档构建自动化工作流,以大幅提升PRD撰写效率。通过结构化需求输入、设计模块化提示词模板,并借助自动化脚本桥接数据与文档,产品经理可将繁琐的文档撰写工作自动化,从而将精力聚焦于产品战略与用户洞察。

weixin_28520495的博客 419

HDU - 1022 Train Problem I【栈】

HDU - 1022 题意: 给定一个入栈顺序和一个出栈顺序,判断是否符合出栈的规则。 #include<bits/stdc++.h> using namespace std; #define endl "\n" int n; string a, b; void run() { vector<int> ans; stack<char> s; int c1 = 0, c2 = 0; while(c2 < n) { if(s.empty(...

lllllan 186

存内计算路线再获加持,清华存内芯片登Science

通过这种方法,可以比较有效的控制二氧化铪忆阻层中的微观变化,以及内部的温度和电场,使得器件具有非常优异的电学特性,而且可以在工厂里大规模生产,推动了高性能忆阻器阵列的诞生。团队搭建了全硬件构成的完整存算一体系统,如下图7所示,在系统里集成了多个忆阻器阵列,并在该系统上高效运行了卷积神经网络算法,成功验证了图像识别功能,证明了存算一体架构全硬件实现的可行性,并且成功实现了以更小的功耗和更低的硬件成本完成复杂的计算[6]。根据测试,在一般神经网络中权重更新的最后阶段,调整步长非常接近0,如图9(C)所示,

PXX12345678的博客 1572

hdu - 1022 题解

题意:火车站有一个铁轨,出口和入口是同一个。给定火车入站序列,问能否调成成出站序列,如果能,输出出站操作。 题解:模拟栈即可,如果栈空,则从入站序列取出首元素压栈,如果栈顶元素与出站序列首元素不同,则从入站序列取出首元素压栈,如果栈顶元素与出站序列首元素相同,则出栈,更新出站序列首元素。如果入站序列已空,而还在尝试取出首元素压栈,则判定为不能调整。 1 #include<iostrea...

远见望远的博客 128

Vue3 - Element Plus 表格组件 el-table “表格行数据中又嵌套了二维对象数组“,按平级循环渲染(嵌套数组视为同级行数据), 对嵌套的数组循环展示为表格,智能合并行或列详细教程

vue3,nuxt3,element-plus,table表格组件,el-table,vue3element表格组件,数据中有二维数组怎么遍历循环显示,表格数据带二级数组怎么循环渲染显示,表格数据中存在一个数组要怎么才能显示到表格,el-table表格合并详细教程示例,table表格如果对象里面还有对象数组那该怎么去渲染,平常都是数组中一个对象渲染成一行,每行中还有嵌套数组怎么办,每个行数据下还有一个数组怎么显示,怎么把表格相同的数据合并为一行,合并上下两行相同数据单元格,合并行或列如果遇到相同单元格就合

🏆 前端领域优质创作者 1万+

电化学-论文分享-NanoStat: An open source, fully wireless potentiostat

本文主要分享论文NanoStat: An open source, fully wireless potentiostat,并记录学习笔记。如果有条件,建议看原文最好。

分享技术笔记,希望对大家能够有一定的帮助,同时也通过归纳总结提升自己的个人能力。 2886

hdu-1022--Train Problem I(栈和队列)

题意描述: 给出列车的数量,让你检查出是否能按照所给的第一个字串的顺序进站按字串二的顺序出站,然后参照样例输出 解题方法: 将字串转化为整型数组判断,进站出站都用一个数组进行标记进站为1出站为2,然后最后判断出站是否能出完即可,输出按照样例输出即可; 下面是原文题目: As the new term comes, the Ignatius Train Station is very busy no...

weixin_44606952的博客 208

[ vulhub漏洞复现篇 ] ActiveMQ反序列化漏洞复现(CVE-2015-5254)

Apache ActiveMQ是美国阿帕奇(Apache)软件基金会所研发的一套开源的消息中间件,它支持Java消息服务、集群、Spring Framework等。由于ActiveMQ是一个纯Java程序,因此只需要操作系统支持Java虚拟机,ActiveMQ便可执行。Apache ActiveMQ 5.13.0之前5.x版本中存在安全漏洞,该漏洞源于程序没有限制可在代理中序列化的类。......

qq_51577576的博客 4458

HDU-1022-Train Problem I(C++ && 简单堆栈)

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 24737    Accepted Submission(s): 9316 Problem Description As the ne

保持对编程的热情! 854

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

HDU 1022 Train Problem I

HDU 1022 Train Problem I题目描述:求解: 题目描述: Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 48735 Accepted Submission(s): 18382 P...

weixin_36343850的博客 192

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

hdu 1022 Train Problem I 栈

Train Problem ITime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3121    Accepted Submission(s): 1148Problem DescriptionAs the new term come

Rachel Zhang的专栏 4535

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

hdu 1022 Train Problem I

   HDU                Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 47175    Accepted Submission(s): 17708   Problem Des...

just do 312

HDU1022 Train Problem I

题目大意:水题一枚,但是自己很水,所以模拟了蛮久.囧.栈模拟. 开了三个栈oo1,oo2,oo3. oo2保存要求火车离开的顺序 oo3模拟火车进站的顺序 oo1是辅助栈,为了方便提取进站的头一列车. 学数据结构的时候没好好写写伪代码,所以模拟的思路一开始一塌糊涂.后来认认真真的写一遍伪代码,思路清晰多了: (1)如果oo3栈不为空,并且栈顶元素和oo2栈顶元素相等的话,那么两个栈都开

muxi@Achilles的专栏 1024

HDU 1022—Train Problem I

题目链接Train Problem I) 思路:现将串1当前位置的元素放入stack中,再在stack中循环判断是否与串2当前(此当前需要与串1区分开来)相等,是:则继续循环并且位置加1,否:则跳出循环进行外圈大循环。这样一来则可判断Yes or No,若Yes则用刚才的方法直接在适当的位置上输出in或out,若No则直接输出。 #include<iostream> #include&...

wanglin007 328

HDU - 1022 Train Problem I

https://vjudge.net/problem/HDU-1022 HDU - 1022 Train Problem I题目AC代码 题目 As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fa

斯文~ 193

HDU1020——Encoding,HDU1021——Fibonacci Again,HDU1022——Train Problem I

这个函数实现了斐波那契数列的一个变体。斐波那契数列通常定义为。,之后每一项都是前两项的和。但在这个变体中,起始的两个数分别是。:此函数用于检查是否能够按照给定的出站顺序(根据FN函数推断出n的规律,进行总结归纳。函数会被调用来显示火车调度的具体步骤。:这是程序的入口点,它读取输入并调用。,表示将要处理的字符串数量。:首先,代码读取一个整数。来模拟车站中的火车。

u014114223的博客 848

HDU - 1022- Train Problem I

HDU - 1022- Train Problem I 题目: As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world v). But here co

qq_44816011的博客 220

【HDU 1022 --- Train Problem I 】栈

【HDU 1022 --- Train Problem I 】栈 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ign...

来日浅谈的博客 531
上一篇: uva-514-Rails(栈)
下一篇: poj-1979-Red and Black
Bigdz
博客等级 码龄10年 10粉丝 33原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址