思维体操: HDU1022Train Problem I
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 38390 Accepted Submission(s): 14423
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.



More details in the Sample Input.
for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output.
3 123 321
3 123 312
Yes.
in
in
in
out
out
out
FINISH
No.
FINISHFor the first Sample Input, we let train 1 get in, then train 2 and train 3.HintHint
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.".
RunId : 21242780 Language : G++ Author : hnustwanghe
Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<stack>
using namespace std;
int main(){
int n;
while(scanf("%d",&n)==1){
if(n == 0){
printf("Yes.\nFINISH\n");
continue;
}
stack<int> S;
string O1,O2;
cin >> O1 >> O2;
int pos = 0;
int a[50],cur = 0;
for(int i=0;i<O1.length();i++){
S.push(O1[i]-'0');
a[cur++] = 1;///入栈
while(!S.empty() && S.top()== O2[pos]-'0' && pos <O2.length()){
S.pop();
pos++;
a[cur++] = 2;///出栈
}
}
if(pos == O2.length() && S.empty()){
printf("Yes.\n");
for(int i=0;i<cur;i++){
printf("%s\n",a[i]<2?"in":"out");
}
printf("FINISH\n");
}
else
printf("No.\nFINISH\n");
}
}
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<stack>
using namespace std; int main(){
int n;
while(scanf("%d",&n)==1){
if(n == 0){
printf("Yes.\nFINISH\n");
continue;
}
stack<int> S;
string O1,O2;
cin >> O1 >> O2;
int pos = 0;
int a[50],cur = 0;
for(int i=0;i<O1.length();i++){
S.push(O1[i]-'0');
a[cur++] = 1;///入栈
while(!S.empty() && S.top()== O2[pos]-'0' && pos <O2.length()){
S.pop();
pos++;
a[cur++] = 2;///出栈
}
}
if(pos == O2.length() && S.empty()){
printf("Yes.\n");
for(int i=0;i<cur;i++){
printf("%s\n",a[i]<2?"in":"out");
}
printf("FINISH\n");
}
else
printf("No.\nFINISH\n");
}
}
思维体操: HDU1022Train Problem I的更多相关文章
- HDU-1022Train Problem I,简单栈模拟;
Train Problem I ...
- HDU1022--Train Problem I(栈的应用)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- 思维体操: HDU1287破译密码
破译密码 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- 思维体操: HDU1049Climbing Worm
Climbing Worm Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 思维体操: HDU1008 Elevator
Elevator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 并查集+思维——The Door Problem
一.问题描述(题目链接) 有n个门和m个开关,每个开关可以控制任意多的门,每个门严格的只有两个开关控制,问能否通过操作某些开关使得所有门都打开.(给出门的初始状态). 二.问题分析 大部分开关问题首先 ...
- 2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心
2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心 [Proble ...
- 2.Web开发过程流程图
转自:https://blog.csdn.net/hello_simon/article/details/19993343 最近公司在进行一系列新模块的开发,在痛苦开发的过程中,大家不时在一起进行总结 ...
- 题解-Koishi Loves Construction
题解-Koishi Loves Construction 前缀知识 质数 逆元 暴搜 Koishi Loves Construction 给定 \(X\),\(T\) 组测试数据,每次给一个 \(n\ ...
随机推荐
- The Preliminary Contest for ICPC Asia Shanghai 2019 L. Digit sum
题目:https://nanti.jisuanke.com/t/41422 思路:预处理 #include<bits/stdc++.h> using namespace std; ][]= ...
- Ubuntu ssh秘钥生成
一,秘钥生成传送 ssh-keygen 选项: -b:指定密钥长度: -e:读取openssh的私钥或者公钥文件: -C:添加注释: -f:指定用来保存密钥的文件名: -i:读取未加密的ssh-v2兼 ...
- C# 更改 Hashtable key 名称
Hashtable ht = new Hashtable(); ht[; ht["B"] = ht["标题"]; ht.Remove("标题" ...
- android底部标题栏的实现
一,使用TabActivity来实现底部导航 http://www.apkbus.com/forum.php?mod=viewthread&tid=125521 这种方法在最新版本的sdk中是 ...
- springboot 配置访问本地图片
spring.mvc.static-path-pattern=/image/** spring.resources.static-locations=file:D://image/
- 地图服务 纬度、经度对应坐标轴x,y
记下,供自己参考,中国地区的经纬度,经度大,纬度小 如上海经纬度为:(经度, 纬度)(y, x)(lon, lat) 121.48 31.22 纬度---lat----x轴 经度---lon---y轴
- (转)搭建自己的Nuget服务器
转:https://www.cnblogs.com/knowledgesea/p/5500954.html 序言 你们公司有没有好多项目,有没有好多类库,你们的类库是在tfs中管理,还是svn或者gi ...
- linux命令--truncate 学习
truncate命令可以将一个文件缩小或者扩展到某个给定的大小 可以利用该命令和-s选项来特别指定文件的大小 1.清空一个文件内容,尤其是log 2. truncate -s 0 test
- Navicat Premium Mac 12 破解方法-亲测成功
参照这2篇文档,破解成功了.操作步骤写的很清楚,不再缀述,只记录一下自己破解过程中,认为要注意的点.以免以后再多花时间熟悉重新熟悉操作步骤 Mac安装Navicat(破解版) Navicat Prem ...
- Openstack 实现技术分解 (2) 虚拟机初始化工具 — Cloud-Init & metadata & userdata
目录 目录 前文列表 扩展阅读 系统环境 前言 Cloud-init Cloud-init 的配置文件 metadata userdata metadata 和 userdata 的区别 metada ...