杭电1022 Train Problem I

『杭电1022』Train Problem I 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 pr 阅读详情

Train Problem I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25879    Accepted Submission(s): 9771


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

题目大意:
        一个火车中转站最多可以停放9辆火车,其车辆进站出站符合先进后出原则,给定进站和出站两个字符串,判断其是不是符合题意,如果符合的话输出其过程。
解题思路
        很明显这是一道可以利用栈解答的题目,因为栈的特性也是先进后出,建立两个字符数组存储给定的两个字符串,然后建立一个栈,建立一个数组存储其操作过程,分别定义指向第一个字符串、第二个字符串、操作过程的指针,然后开始循环操作:如果栈空则进栈,字符串A指针+1;如果不空则栈顶元素跟字符串B[字符串B指针]比较,同则出栈且字符串B指针+1,否则字符串A[字符串A指针]入栈且字符串A指针+1,直到字符串B指针跟字符串B长度相等。其中利用过程数组脚码来标记每次操作,进栈则为1,出栈则为0。

#include<stdio.h>
#define max 20
char in[max],out[max],target[max],stack[max];//进入顺序 步骤 目标顺序 栈 当前在车站里的火车
int main()
{
	int n,top,nowpos,head,step;//top栈顶  nowpos达成目标进度  head车队头 step 步骤数 
	while(~scanf("%d",&n))
	{
		scanf("%s %s",in,target);
		top=nowpos=head=step=0;
		while(head<n)
		{
			stack[++top]=in[head++];//stack[1]=int[0]先把车一个个进栈 
			out[step++]='1';//步骤进去为1出去为0 
			while(top&&stack[top]==target[nowpos])//循环直到车一个个进栈,最后一辆车的编号和出去第一辆车编号相同进入循环 
			{
				top--;//出去一辆栈顶-1 
				nowpos++;//完成进度加1 
				out[step++]='0';//出去的步骤加1; 
			}
		}
			if(nowpos==n)//如果完成的进度数等于n则可以完成过程 
			{
				printf("Yes.\n");
				for(int i=0;i<step;i++)
				{
					if(out[i]=='0')
					printf("out\n");
					else
					printf("in\n");
				}
				printf("FINISH\n");
			}
			else
			printf("No.\nFINISH\n");
	}
	return 0;
} 


解决ArcGIS-OpenStreetMap Toolbox-Load OSM File错误 在安装成功OpenStreetMap Toolbox后,首次运行Load OSM File工具,出现以下错误 阅读详情

相关推荐

DESeq2实战:如何用LRT检验分析基因表达随时间变化的模式(附完整代码)

本文详细介绍了如何使用DESeq2中的LRT检验分析基因表达随时间变化的模式,包括实验设计、数据预处理、模型构建、结果提取与可视化等完整流程。通过实战案例和完整代码,帮助生物信息学研究者掌握时间序列RNA-seq分析的核心技术,特别适合需要快速上手的实践者。

weixin_42620255的博客 467

杭电OJ【1022】Train Problem I 栈

解题思路: 进栈出栈问题。 代码: #include #include #include using namespace std; int main() {     int n,io[100];     char in[100],out[100];     while(~scanf("%d %s %s",&n,in,out))     {         stac

戦う! 276

保姆级教程:用GROMACS的FEP方法计算小分子结合自由能(附完整mdp配置)

本文提供了一份详细的GROMACS自由能微扰(FEP)计算教程,涵盖从系统准备、参数配置到结果分析的全流程。通过具体案例演示如何计算小分子结合自由能,包括λ窗口设计、动力学参数优化及并行化执行技巧,帮助研究者克服FEP计算中的常见问题,获得可靠的自由能数据。

weixin_30598225的博客 353

杭电OJ---1002

#include&lt;iostream&gt; #include&lt;string&gt; #include&lt;algorithm&gt; using namespace std; string add(string a, string b)//数字长度短的永远在a里存储 { string sum; reverse(a.begin(), a.end());//先将两个字符串反转 re...

ARTELE的博客 482

几率大的网络安全面试题(含答案)

其他篇章:Java校招极大几率出的面试题(含答案)----汇总 本文面试题汇总: 防范常见的 Web 攻击 重要协议分布层 arp协议的工作原理 rip协议是什么?rip的工作原理 什么是RARP?工作原理 OSPF协议?OSPF的工作原理 TCP与UDP区别总结 什么是三次握手四次挥手? tcp为什么要三次握手? dns是什么?dns的工作原理 一次完整的HTTP请求过程 Cookies和ses...

睶 6万+

FCL碰撞检测库在Windows下的编译与配置(MinGW+CMake)

本文详细介绍了在Windows系统下使用MinGW和CMake编译配置FCL碰撞检测库的完整流程。内容涵盖MinGW-w64、CMake的安装与环境配置,关键依赖库Eigen和libccd的安装,以及FCL源码的编译、安装与实战测试。重点解析了CMake配置命令中的关键参数与常见错误解决方案,旨在帮助开发者高效完成FCL在Windows平台的部署,适用于机器人、游戏物理引擎等需要精确碰撞检测的开发场景。

sunny的博客 483

杭电ACM1022Train Problem I

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1022 解题思路:针对每一个火车,有入站出站2种状态,判断是否入站条件为:首先栈为空,入栈;再次栈不为空并且顶栈元素不等于出栈的序列元素,出栈条件:栈不为空,栈顶元素等于出站序列;记录出入状态用记录数组(大小是2倍序列)数组中下标用2个变量控制的巧妙运用;最后用战是否为空来判断出站序列

SiFa的博客 584

uniapp:安卓苹果APP判断是否授权开启手机位置服务+弹框引导跳转到用户手机设置位置服务开启页面,uniApp app判断是否授权位置信息权限如果位置是关闭状态则提示用户(跳转各机型位置设置页面)

uniapp APP判断是否开启位置信息服务&&判断是否授权位置信息权限,uniappapp定位权限被拒绝后,询问是否开启授权并跳转到手机设置页面,uniapp APP端 定位未授权 去手机设置里开启定位,uniapp提示用户开启定位,跳转到开启定位页面,uniapp获取当前位置及检测授权状态,uniapp中获取位置信息处理,uni-app实现定位功能_uniapp获取定位位置信息,uniapp中app是否开启定位,app获取地理位置,uniapp打开位置权限设置页面IOS,用户并没有开启微信信息服务或者没

✅ 精选推荐文章 4342

HDOJ 1022 Train Problem I(栈)

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

阿金的ACM 853

信息传输仿真:卫星通信系统仿真_(12).卫星通信系统仿真软件介绍

卫星通信系统仿真软件是进行卫星通信系统设计和性能优化的重要工具。通过这些软件,用户可以模拟和分析各种通信场景,验证不同的通信协议和算法,优化系统参数和配置。本节介绍了 MATLAB Simulink、NS-3、OPNET 和 SystemVue 的基本功能、特点和配置方法,希望对读者在选择和使用仿真软件时提供参考。在实际应用中,建议根据项目需求和团队能力,综合考虑选择合适的仿真软件。

2401_87715305的博客 1278

【智能车Code review】——环岛的判定与补线操作

【1】效果展示图 状态1、状态2 状态3 状态4、状态5 状态6 状态7 状态8 【2】状态机设定需要的参数 以右环岛为例: k_left:左线的斜率 rou_of_left:左线的方差 last_rou_of_left:上一帧的左线方差 l_start:左线第一行为黑的所在行 right_turn_down; right_turn_middle; right_turn_up; 左线的下、中、上拐点 fiv_width[i]:第i行的赛道宽度 leftline_du

hanhan的博客 2万+

hdu 1022 简单的栈应用

本题链接:点击打开链接                          Train Problem I   Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35730    Accepted Submission(s): 1347...

怒╯ér╭飞 1809

YOLOv8 置信度阈值 (conf) 和 IoU 阈值 (iou) 详解:如何平衡漏检与误检?

摘要 本文深入探讨了YOLOv8目标检测模型中两个关键参数——置信度阈值(conf)和IoU阈值(iou)的核心作用。文章从目标检测的基础概念出发,解释了置信度分数反映模型预测可靠性,IoU衡量预测框重叠程度。重点剖析了非极大值抑制(NMS)机制如何通过这两个阈值进行预测框筛选:置信度阈值作为初筛门槛,IoU阈值决定重叠框的取舍。通过生动比喻和可视化图表,阐述了合理调节这两个参数能有效平衡误检与漏检问题,是优化YOLOv8模型实际表现的重要技巧。全文以实践为导向,帮助开发者掌握成为"调参大师&qu

深耕 Vue 生态与 JS/TS 技术,聚焦组件封装、响应式原理、TS 类型设计,解析工程化配置与性能优化方案。同时分享 YOLOv8 目标检测实战、AI 大模型面试核心考点,以代码实例拆解技术实现与业务解法。 1247

杭电acm1022 Train Problem I

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

cwhong_723的博客 780

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

杭电1022(栈的运用) 之 Train Problem I

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 t

ESESZB的博客 532

efm32 入门.pdf

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

杭电1022 Train Problem I

/*********************************  *    日期:2011-3-12  *    作者:SJF  *    题号:杭电1022  *    题目:Train Problem I  *    结果:AC  *    题意:  *    总结: **********************************/ #include #incl

落日小屋 1136

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

【杭电】[1022]Train Problem I

容易想到用栈模拟 这里用两个数组储存数据 然后进行比较 (随之就能出栈或者先保留看进行完下一个之后能否出栈) 并用一个flag数组记录所需操作最后将出栈数与数据数对比 如果相同则说明此操作成立

BoilTask Talk Show 615

杭电hduoj 1022 Train Problem I

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 算法特工队QQ群:979618872 (伸手党绕边,欢迎有良好基础的人加入) // // Created by Leo Lee on 2019/4/4. // #include <iostream> #include <algorithm> #include <...

tobe_numberone的博客 288

杭电OJ - 1022 Train Problem I(栈应用)

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

TimeDeath的博客 299

杭电acm—1022 Train Problem I

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 46308    Accepted Submiss...

HGS的博客 668

【杭电oj】1022 - Train Problem I(栈)

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

wyg1997 933

杭电1022-Train Problem I

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

ecjtu_acm_菜鸟—鱼尾尾 1142

杭电OJ 1022:Train Problem I

这个题目主要就是模拟出栈和入栈,其实不难就是有点麻烦。话不多说,直接上代码: #include #include using namespace std; int main(){ int n;int in[10],out[10];stack S; int result[20];char t1[10],t2[10]; while(scanf("%d\n",&n)!=EOF){ whi

533
上一篇: 初试栈问题ny2括号配对
下一篇: 杭电1870愚人节礼物 技巧性代码VS用栈代码
JINKELA_
博客等级 码龄11年 75粉丝 178原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值