HDU 1022 Train Problem I (栈)

Train Problem I(火车进站问题)hdu1022 问题 Train Problem I 假设杭州东火车站只有一条铁路,并且所有火车都从一侧进来,从另一侧出去。那么,如果火车A先进站,然后火车B在火车A离开之前就进站,那么火车A直到火车B离开后才能离开,可参见下图。 现在,假设车站中有n(n<=9)列火车,所有火车都有一个ID(从1到n的编号),火车以O1的顺序进站,您的任务是确定火车是否可以按O2顺序出站。 思路 1、初始时刻,p1、p2分别指向入站、出站序列的第一个元素 2、若p1指向入站序列尾部,则5;否则,将p1指向的入站元素压栈 3、栈 阅读详情

Train Problem I

http://acm.hdu.edu.cn/showproblem.php?pid=1022


Time Limit: 2000/1000 MS (Java/Others)    

Memory Limit: 65536/32768 K (Java/Others)


Problem 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 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
Hint
Hint
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.".


使用栈或者数组实现,用一个指标记录应该出来的火车的编号,然后检查进来的火车,如果相同就出去并检查栈内的火车,不同就压入栈。


完整代码:

/*15ms,228KB*/

#include <cstdio>
#include <cstring>

int n, top, t, h;
char in[10], out[10], s[10], d[10];

int main(void)
{
	while (~scanf("%d", &n))
	{
		top = 0;
		t = h = 0;
		scanf("%s%s", in, out);
		for (int i = 0, j = 0; i < n; i++)
		{
			s[top++] = in[i];
			d[t++] = 1;
			while (top > 0 && s[top - 1] == out[j])
                top--, j++, d[t++] = 0;
		}
		if (top == 0)
		{
			puts("Yes.");
			for (int i = 0; i < t; i++)
				puts(d[i] == 0 ? "out" : "in");
		}
		else
			puts("No.");
		puts("FINISH");
	}
	return 0;
}



centos7安装db2 version11.1 阅读详情

相关推荐

【Docker】Docker安装Hadoop分布式集群

hadoop目录安装在:/usr/local/hadoop-2.7.0/etc/hadoop。访问Hadoop102:9870,查看是否能够看到hdfs界面。访问hadoop103:8088,查看能够看到yarn界面。在yarn上可以看到执行情况。

weixin_46429290的博客 3468

HDU 1022

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

http://kingim.cn/ 1168

H3C VRF实验

POP-vpn-instance-RT1]route-distinguisher 11:11 # VPN实例-RT1的路由区分器值11:11。配置路由泄露,其实就是在一个VPN示例中添加另一个VPN实例的下一跳,比如在VPN实例RT1中添加去往SRV的默认路由。但是也有了一个新的问题,那就是RT1、RT2和RT3也能互访了,这让VPN实例变得没有意义了。[POP]ip vpn-instance RT1 #配置vpn实例-RT1。绑定了VPN实例,所以要把路由添加到VPN实例POP中。

m0_68698993的博客 4045

1022 Train Problem I

Train Problem ITime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6295    Accepted Subm

734

GBase8a-GDCA认证考试-复习参考题

为提升产品服务水平定期举办GBase产品认证培训,培训更多GBase数据库专业人员,满足用户快速成长的业务需求,建设GBase产品生态。请注意甄别,根据所学知识综合判断,正确率97%(97分)。

weixin_41826637的博客 2398

从 CDS 接口到 ABAP 运行时,深入理解 SAP RAP Custom Entity

CDS Custom Entity 是一种非 SQL、瞬态的 CDS 实体,不依赖 HANA SQL 读取数据,而是通过 ABAP 类实现查询逻辑(如 RFC、OData、BAPI 等)。它在 CDS 层定义数据契约(字段、键、关联、注解),由 @ObjectModel.query.implementedBy 指向实现 IF_RAP_QUERY_PROVIDER~SELECT 的类,真正执行数据获取。适用于无法用 SQL 表达的数据源,如远程系统或 API。其核心是“接口 + 实现”模式,运行时由 RAP

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 179

Train Problem I(经典栈)

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

不会思考的机器 2499

Android 15.0 添加自定义服务,并生成jar给第三方app调用

在15.0系统ROM产品定制化开发中,由于需要新增加自定义的功能,所以要增加自定义服务,而app上层通过调用自定义服务,来调用相应的功能,所以系统需要先生成jar,然后生成jar 给上层app调用,接下来就来分析实现的步骤,然后来实现相关的功能 从而来实现所需要的功能

安卓兼职framework和app工程师的博客 677

hdoj1022 Train Problem I(栈的简单应用)

题目很长,大意是给你两个序列,要你判断是否能够通过入栈出栈操作将第一个序列变为第二个序列。 考察栈的简单运用。 #include using namespace std; int main() { char s1[12],s2[12],stack[12]; int top,n,i,j,k; int gg[22]; while(cin>>n>>s1>>s2) { top=-1;j

CqZtw的博客 439

让openclaw接入web端的deepseek或着qwen,使用无限token

🪟 Windows: 提供原生的 PowerShell 一键安装支持!配置过程和官方版本是相同的,唯一的区别就是再选则model时要选择带Browser字样的deepseek或者qwen。安装之前需要先清理官方版本的安装痕迹,否则openclaw版本跳转不到这个中文版本。因为此版本与官方版本存在代差,在配置飞书时可能会出现无法安装飞书的情况。剩下的配置保持和官方版本一致操作即可。选中之后需要进行一次网页端的登录。登录后会出现可选择的model。安装完成后会跳到这个中文界面。涉及到接入飞书机器人的操作。

z1872385的博客 310

RK3568平台开发系列讲解:内核启动流程

第 493 行的 ENTRY 指明了了 Linux 内核入口,入口为stext,stext 定义在文件arch/arm/kernel/head.S 中 , 因此要分析Linux 内核的启动流程,就得先从文件arch/arm/kernel/head.S 的 stext 处开始分析。_mmap_switched 定义在文件 arch/arm/kernel/head-common.S,__mmap_switched 最终会调用 start_kernel 函数。⑥、r2=atags 或者设备树(dtb)首地址。

内核笔记 224

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

从你的全世界路过---陌陌X-SIGN还原

我们上期介绍了hook 接口方式,今天我分析so 层。学习是为了复杂的事情简单化。不用如此繁琐。跟进native_sdbyecbu37x这个函数,我们f5看伪代码 v13 = sign(v9, v10, v11, a6); 跟进这个函数 代码如下(示例): 2.代码贴入 SHA消息摘要java代码如下: java 代码如下(示例): 总结 算法,结合动态调试!

任雪飘的博客 2304

hdu 1022 Train Problem I(栈的模拟)

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 给定入栈顺序,问能否按照某个方式出栈。 思路: 直接模拟即可。 代码: #include #include #include #include #include #include using namespace std; char s1[15],s2[15]; i

hahahaha 530

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Devexpress16.2.6破解工具

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

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

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

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): 53352Accepted Submission(s): 20006 Problem Description As the new term...

Twinkle_sone的博客 317

【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

ACM-栈之Train Problem I——hdu1022

Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18202 Accepted Submission(s): 6819 Problem Description As the new term c

继续激情,继续奋斗。 1546

HDU - 1022 - Train Problem I(栈)

HDU 1022.Train Problem I(栈) Time Limit: 2000/1000 MS (Java/Others)       Memory Limit: 65536/32768 K (Java/Others) Problem DescriptionAs the new term comes, the Ignatius Train Station is very busy

在努力! 746

HDU 1022 Train Problem I (STL 栈模拟)

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

AC_Dreameng 2266

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): 51413 Accepted Submission(s): 19341 Problem Descri...

dmen22330的博客 156

HDU 1022 Train Problem I 简单的栈

题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1022 (杭州G20期间 HDU域名可能随时更换) Problem DescriptionAs the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get

376

Train Problem I hdu 1022 栈

http://acm.hdu.edu.cn/showproblem.php?pid=1022//学了数据结构,一点也不会用,好郁闷的;//这是栈很基础的内容,参考了别人的,终于写起来有点感觉// 3 123 123   123 213  这两种情况是可以的#include//2275912 2010-03-31 22:18:55 Accepted 1022 0MS 352K 831 B C++

悔惜晟 485

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): 26020    Accepted Submission(s): 9828 Problem Description As the new

dxx_111的博客 413

HDU1022 Train Problem I 栈的模拟

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 栈的模拟,题目大意是已知元素次序, 判断出栈次序是否合理。 需要考虑到各种情况, 分类处理。 常见错误:使用前未清空栈 使用STL思路较为清晰 代码附上, 欢迎各位大神指点~~ #include <cstdio> #include <stack> #in...

weixin_30275415的博客 160

hdu1022 Train Problem I 栈的应用

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 29193    Accepted Submission(s): 11080 Problem Description As the new t

EventQueue的博客 420

hdu 1022 Train Problem I(栈)

题目链接:hdu 1022 Train Problem I 题目大意:有一列火车,给出车厢数和车厢的序列,目标序列,通过一个类似栈的车轨,能不能变成目标序列,能得话输出方案。 解题思路:虽说有一种遍历的方式可以判断,即当目标序列存在a,b,c这样的序列时,若f(a) > f(c) > f(b)时即为不可变为的序列,(f(i)代表第i个元素在原序列中的出现的顺序),但对与本体我觉

不慌不忙、不急不躁 1399
上一篇: Codeforces Beta Round #74 (Div. 2) / 90B African Crossword (模拟)
下一篇: POJ 3233 Matrix Power Series (矩阵&快速等比数列求和取模)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值