HDOJ1022. Train Problem I(栈)

COMSOL多物理场仿真:瓷绝缘子电热耦合建模与优化策略 本文详细介绍了使用COMSOL Multiphysics进行瓷绝缘子电热耦合仿真的完整流程与优化策略。文章阐述了电热耦合效应的工程意义,并逐步讲解了从几何建模、材料定义、物理场设置到边界条件与网格划分的关键步骤。重点分析了如何通过焦耳热耦合实现电场与温度场的双向交互,以及如何利用仿真结果进行参数化优化和瞬态故障模拟,为提升电力设备可靠性提供有效的数字化设计工具。 阅读详情

Train Problem I

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


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辆车。现在有一个n辆车的进入和离开的序列O1和O2,且先进入的车只能在后进入的车离开后才能离开,问此序列是否符合要求?如果能,输出"Yes"及这n辆车的进出方案,否则输出"No."。

        不难想到用栈模拟上述过程,但需要特别注意的是:n辆车不一定是一次性进入或离开的。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
const int maxn=15;
int n;
char O1[maxn],O2[maxn];  //n辆车的进入.离开序列 
char result[2*maxn][5];  //进出方案 
stack<char> st;
int main()
{
	int i,j,ans;
	while(scanf("%d %s %s",&n,O1,O2)!=EOF)
	{
		i=j=ans=0;
		//开始栈为空,O1序列第一个元素入栈 
		st.push(O1[i]);
		strcpy(result[ans++],"in");
		while(i<n && j<n)
		{
			//栈不空 且栈顶元素与O2序列当前元素相同 
			if(!st.empty() && st.top()==O2[j])
			{
				//则将当前栈顶元素出栈,并继续考察O2序列下一元素 
				j++;
				st.pop();
				strcpy(result[ans++],"out");
			}
			//否则O1序列当前元素入栈 
			else
			{
				//栈顶元素与O2序列当前元素不同,且O1序列中所有元素均已入栈
				//则此方案不符合要求 
				if(i==n)
					break;
				st.push(O1[++i]); 
				strcpy(result[ans++],"in");
			}
		}
		if(i==n)
			printf("No.\n");
		else
		{
			printf("Yes.\n");
			for(i=0;i<ans;i++)
				printf("%s\n",result[i]);
		}
		printf("FINISH\n");
	}
	return 0;
}


Claude Code教程(二) | Claude Code 核心信息与使用指南 Claude Code 核心信息与使用指南 阅读详情

相关推荐

期货分仓系统CTP协议/国内期货软件源码

期货分仓系统与CTP协议以及国内期货软件源码是期货交易技术领域的几个重要方面。

q2247238820的博客 965

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

Life is Float. 668

GB28181安防平台未授权访问漏洞:原理、复现与修复指南

未授权访问漏洞是Web安全中常见的访问控制缺陷,其本质在于应用在提供对敏感功能或数据的访问前,未能对请求者的身份和权限进行充分验证。从技术原理上看,这类漏洞常源于拦截器配置错误、安全注解遗漏或自定义校验逻辑缺陷,导致本应受保护的API接口被意外暴露。在工程实践中,此类漏洞危害巨大,攻击者无需登录即可直接访问系统核心接口,可能引发敏感信息泄露、权限提升甚至系统接管。尤其在安防监控、物联网管理平台等场景中,一旦涉及用户管理接口(如`/api/user/**`),风险会急剧放大。本文以GB28181视频监控管理平

weixin_30271335的博客 442

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): 25517    Accepted Submission(s): 9640 Problem Description As the new te

滴水穿石,慢慢积累,总会有成果 404

Frida提取Cocos游戏XXTEA密钥的实战方法论

XXTEA是一种轻量级分组加密算法,广泛用于移动端游戏通信保护;其128位密钥的安全性直接决定网络协议逆向成败。在Cocos引擎生态中,密钥常以静态常量、JNI动态传递或Native运行时派生三种形态存在,导致传统静态分析失效。Frida凭借跨Java/Native注入能力与内存实时观测优势,成为捕获密钥‘出生瞬间’的关键工具——尤其适用于hook xxtea_encrypt函数入口、监控JNI参数传递、设置内存断点追踪派生过程等场景。本文聚焦Cocos2d-x与Cocos Creator项目,覆盖从密钥识

weixin_33509600的博客 422

利用Openlayers4实现地图遮罩效果(二)

之前实现的遮罩效果,在深色背景的底图上,对要突出的区域采用半透明遮罩,以此来突出该区域。但是有时底图颜色偏白,这时候不再适合对要突出的区域采用遮罩,而是要对突出区域之外进行遮罩处理。两种效果的对比入下图: ...

此爱如少年 6403

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): 25857    Accepted Submission(s): 9761 Problem Description As the

网络二师兄 581

UVM实战 卷I学习笔记1——简单的UVM验证平台:只有driver

目录验证平台的组成最简单的验证平台——只有driverUVM如何搭建driver:加入factory机制加入objection机制加入virtual interface 个人《UVM实战卷I》学习随手笔记,此书作者:张强 验证平台的组成 一个验证平台要实现的基本功能: 模拟DUT的各种真实使用情况——给DUT施加各种激励→driver实现激励功能; 根据DUT的输出判断DUT行为是否与预期符合→scoreboard(也称为checker)——需注意判断的东西和判断的标准是什么; 收集DUT的输出并传递

weixin_41979380的博客 3897

模拟栈的出入 HDOJ 1022 Train Problem I

题目传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1022题目大意是给出一个入栈的序列,判断一个给出的序列是否可能是一个合法的出栈序列,若是,给出入栈和出栈的过程。#include <iostream> #include <cstring>using namespace std;int main(int argc, char const *argv[

nNbS 350

RK3568平台(camera篇) MPP编码

同芯片的差异,为使用者提供统一的视频媒体处理接口(Media Process Interface,缩写 MPI)。瑞芯微提供的媒体处理软件平台(Media Process Platform,简称 MPP)是适用于瑞芯微芯片系列的。mpi_enc_test 的命令参数中,图像宽度(w)图像高度(h),码流类型(t)为强制要求参数,其他参。视频拷贝,缩放,色彩空间转换,场视频解交织(Deinterlace)数如输入文件(i),输出文件(o),编码帧数(n)等为可选参数。设置一些MPP的模式。

weixin_49303682的博客 7382

SAP S/4HANA 数据归档的实施方法

实施 SAP S/4HANA 数据归档是一个系统的过程,涉及到策略的定义、技术的执行以及后续的维护和验证。正确的归档策略不仅能优化系统性能,还能帮助企业降低运营成本,确保数据安全,并符合相关法律法规的要求。通过以上案例,我们可以看到不同行业如何依据自己的业务需求和法规要求,利用 SAP S/4HANA 的强大功能来实现数据归档的目标。这些实践证明了数据归档在现代企业信息管理中的重要地位和作用。

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

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 854

Python爬虫实战——如何自动爬取百度搜索结果页面

本文介绍了如何使用Python爬虫抓取百度搜索结果页面的内容,包括如何构建搜索URL、获取页面HTML、解析内容、处理翻页以及存储数据等。通过该教程,您可以轻松实现批量抓取百度搜索结果,并为后续的数据分析和处理打下基础。希望本文能为您在爬虫开发、数据分析等领域提供帮助。如果您在实际应用过程中遇到问题,可以参考反爬虫应对策略,并结合实际需求进行调整。

2201_76125261的博客 1712

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): 26563    Accepted Submission(s): 10043 Problem Description As the new t

平平淡淡才是真 358

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

HDOJ1022 Train Problem I 栈模拟

#include"stdio.h" #include"string.h" main() { char in[10],out[10],stack[10],str[2][4]={"out","in"}; int n,i,top,ans[20],j,rear,flag,k; while(scanf("%d %s %s",&n,in,out)!=EOF) {

Kizuki 476

Devexpress16.2.6破解工具

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

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): 28666    Accepted Submission(s): 10889 Problem Description As the new t

Calm微笑 489

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDOJ Train Problem I 1022(栈)

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

豫帝哥哥 946

hdoj 1022 Train Problem I (第一次接触栈)

思路:定义一个栈,将火车一个个放入栈中,直到出现一个火车(该火车要先出去),等所有火车都进入完栈,并且都出完栈,返回yes+方法,否则返回no; 代码如下:#include #include #include /* run this program using the console pauser or add your own getch, system("pause") or inpu

摆渡人的博客 188

HDOJ 1022 Train Problem I(栈)

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

SimonCoder的专栏 625

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

HDOJ/HDU 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 th

谙忆-陈浩翔 8987

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): 20743    Accepted Submission(s): 7806 Problem Description As the new te

mwangyongqi的专栏 482

HDOJ题目1022Train Problem I(栈的模拟)

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

Jogging_Clown 517

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

HDOJ 1022 Train Problem I (Stack)

火车进出站 Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26211 Accepted Submission(s): 9906 Problem Description As the new term comes, the Ignatius Train Station is very busy

jianjun的专栏 435

HDOJ 1022 Train Problem I 超详细

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

qascetic的博客 231
上一篇: NYOJ176. 整数划分(二)(计数DP)
下一篇: HDOJ2046. 骨牌铺方格(简单基础递推)
锐不可当cr
博客等级 码龄10年 288粉丝 310原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址