HDU 1022 Train Problem I (栈)

CS1237卡尔曼滤波实战:如何用24位ADC实现电子秤级精度? 本文详细介绍了如何利用CS1237 24位ADC芯片结合卡尔曼滤波算法实现电子秤级精度测量。通过解析CS1237硬件特性、卡尔曼滤波原理及STM32驱动优化,提供了一套完整的解决方案,包括多通道支持、驱动代码实现和性能调优技巧,适用于工业测量和嵌入式开发领域。 阅读详情

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



鸿蒙ArkUI内部API10以及11开发,输入框唤起输入法键盘,页面会被顶起的解决办法 阅读详情

相关推荐

ggml_cgraph 详解

是 GGML 库的(Computation Graph)结构,它是深度学习框架的核心,用于表示、优化和执行神经网络的计算过程。

zhouzwd87的专栏 1203

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

海康视觉相机驱动软件MVS参数配置全攻略(附接线图+避坑指南)

本文提供了海康视觉相机驱动软件MVS从硬件连接到软件参数配置的完整指南。详细解析了供电与通讯线缆的区分、PNP/NPN信号逻辑的接线避坑方法,并重点阐述了MVS软件中触发模式、网络IP配置、图像采集及光源控制等核心参数的设置技巧,旨在帮助用户快速完成相机调试,实现稳定高效的图像采集。

weixin_29204205的博客 399

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

基于立创EDA的IP5389BZ+IP6829 100W有线15W无线带屏充电宝DIY全流程解析

本文详细解析了基于立创EDA平台,采用IP5389BZ和IP6829芯片DIY一款100W有线快充、15W无线充电并带显示屏的移动电源的全过程。内容涵盖核心功能规划、硬件选型、电路设计、PCB布局、焊接组装、分步调试以及软件逻辑,为电子爱好者提供了一份从原理到实践的完整指南,并重点强调了电池安全与IP6829供电电压等关键注意事项。

weixin_34374684的博客 307

HTML满屏跳动的爱心(完整代码)

HTML语言实现满屏跳动爱心的完整代码。

AIGC 12万+

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

文献综述三大痛点用AI轻松解决!借助Gemini 3 Pro搞定检索难、阅读慢、框架乱问题(附 AI 提示词)

4)“漏斗式”结构:先介绍宏观领域的研究现状,再缩小范围,聚焦于与你课题直接先关的子领域,深入探讨与你研究变量直接相关的文献, 指出前人没做过、没做全或结论有矛盾的地方,再顺势提出你的研究课题,这种结构逻辑最清晰,能直接引导读者发现你研究的必要性。想要有针对性的搜到相关文献,必须先把模糊的研究题目拆解成精准的检索语言,这个时候就需要建立一个关键词矩阵,如核心词、同义词、学术术语、上下位词,以及对应的英文表达。请围绕【我的研究主题/关键词】,检索近5年发表的高被引的中英文文献,优先选择顶刊综述/论文。

智能AI让学术科研更容易 277

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

用扩展点为 Fiori Elements 添加自定义动作:从原理到落地的完整实践

本文介绍了如何在基于OData V4的Fiori Elements应用中通过Extension Points添加自定义Action按钮。主要内容包括: 扩展点动作与标准注解动作的区别:扩展点用于非标准前端流程、组合操作等场景,需通过extensionAPI与框架交互。 扩展点动作的插入位置:可放置在List Report表格工具栏、Object Page页眉/页脚/Section工具栏等位置,并说明了相应的manifest.json配置节点。 配置模型与处理函数契约:详细说明了press、visible/e

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

解锁轻量化网络实验室:在 Containerlab 中部署 Cisco IOL 设备的详细教程

Cisco IOS On Linux(IOL)是 Cisco IOS-XE 的简化版,它是 Cisco IOS 的一种轻量级实现。IOL 并不需要完整的虚拟机(Virtual Machine, VM)环境,可以直接在 Linux 上运行,极大地减少了对系统资源的需求。IOL 节点通过更精简的方式提供了 Cisco IOS 功能,适合构建实验室、测试网络协议和验证网络设计。

网络技术联盟站 476

[HDOJ1022]Train Problem I

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 手写栈,模拟出入的过程。很简单,不停入栈,如果和当前要求出站车辆相同的话就出站,否则继续入栈。 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #...

weixin_30387339的博客 146

大厂校招:星宸科技嵌入式面试及参考答案(5万字长文)

当一个新的硬件设备被插入系统时,内核会发送一个设备事件通知 udev,udev 会根据设备的属性和规则,为该设备创建一个合适的设备文件。通过去除不必要的驱动程序、禁用不需要的功能、选择合适的内核配置选项、优化内核编译选项和定制内核模块等方法,可以减小内核的大小和复杂性,提高系统的性能和稳定性。上半部通常是在中断关闭的情况下执行的,以确保中断处理的原子性。处理碎片化内存是内存管理中的一个重要问题,可以采用内存压缩、内存池管理、伙伴系统、首次适应算法和最佳适应算法等方法来减少内存碎片的产生,提高内存的利用率。

大模型大数据攻城狮的专栏 2927

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的专栏 4534

efm32 入门.pdf

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

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

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 529

Camera2Demo

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

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

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

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

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的博客 315

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

来日浅谈的博客 530

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

继续激情,继续奋斗。 1544

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 2264

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
上一篇: 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、付费专栏及课程。

余额充值