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): 24377 Accepted Submission(s): 9196
3 123 312
in
in
in
out
out
out
FINISH
No.
FINISH
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.".
#include<stdio.h>
#include<cstring>
using namespace std;
int main()
{
char o1[],o2[],stack[];
int n,A=,B=,top=,inout[],flag=,ok; //用inout数组来保存压栈和出栈,1为压,0为出
while(scanf("%d %s %s",&n,o1,o2)!=EOF)
{
memset(inout,,sizeof(inout));
ok=;
A=;
B=;
flag=;
top=;
while(B<=n)
{
if(o1[A]==o2[B]) //当前进栈的车与目标顺序中当前列车一致,即进站后立即出站
{
A++;
B++;
inout[flag++]=;
}
else if(top&&stack[top]==o2[B]) //上一种情况不符合,栈顶的列车与目标顺序当前列车一致,即只需出站
{
top--;
B++;
inout[flag++]=;
}
else if(A<=n) // 上两种情况均不符合,只需要压栈
{
stack[++top]=o1[A++];
inout[flag++]=;
}
else //上述三种情况均不符合,此时A>n
{
ok=;
break;
} }
if(ok)
{
printf("Yes.\n");
for(int j=;j<flag-;j++)
if(inout [j]==)
printf("in\nout\n");
else if(inout[j]==)
printf("in\n");
else if(inout[j]==)
printf("out\n");
printf("FINISH\n");
}
else
printf("No.\nFINISH\n");
}
}
HDU_1022_Train Problem I的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.
Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [LeetCode] Water and Jug Problem 水罐问题
You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- 转:js点击事件在ios中失效的3种解决方案
ios中不允许将点击事件绑定在document或者body上,如果绑定上的话将会失效.解决方案: 例如: $(document).on('click', '#generate', function ...
- nyoj 739 笨蛋的难题四
笨蛋难题四 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描写叙述 这些日子笨蛋一直研究股票,经过调研.最终发现xxx公司股票规律,更可喜的是 笨蛋推算出这家公司每天的股价, ...
- 怎样在gluster的源代码中加入自己的xlator
本文并不说明怎样编写一个xlator.在glusterfs3.6.1下验证成功 目标在glusterfs-3.6.1/xlators/debug/下建立一个自己的xlator库并能够统一安装到系统文件 ...
- hdu1162
#include<cstdio> #include<cmath> #include<climits> #include<algorithm> #defi ...
- js全局替换空格,制表符,换行符
this.value = this.value.replace(/\s+/g,'') "/ "这个是固定写法, "\s"匹配任何不可见字符,包括空格.制表符.换 ...
- [翻译角]Headline English: A Captain Should Be Pitch Perfect at a Multitude of Skills (ESLPOD Blog)
以下转自www.eslpod.com,翻译为本人添加.其余版权均归原网站所有. ESLPOD是一个英语学习网站,我最初知道这个网站,是因为“奶爸”<把你的英语用起来>(电子版3元)一书的推 ...
- 解决Eclipse alt+/不出来提示的问题
1. 检查windows ——preferences ——java ——editor —— content assist - advanced,在右上方有一行“select the proposal ...
- git log 常用选项
git log 常用选项 -p 按补丁格式显示每个更新之间的差异. jiqing@Ubuntu:/home/wwwroot/default/5hao/sheep$ git log -p commit ...
- Tomcat + solr5.2.1环境搭建
1. 下载solr并解压后的目录为:E:\solr-5.2.1 , http://lucene.apache.org/solr/downloads.html 2. 将solr部署到Tomcat中 ...
- Netty,Thrifty
小白科普:Netty有什么用? https://mp.weixin.qq.com/s/PTKnRQ_hLf8BBPYnywLenA Thrifty 是基于.net Attribute 实现了标准 Th ...