思维体操: 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\ ...
随机推荐
- 6423. 【NOIP2019模拟11.11】画
题目描述 Description Input Output Sample Input 3 2 3 3 6 5 1 2 1 3 Sample Output 15 Data Constraint 题解 迫 ...
- tomcat7 与tomcat8 使用tomcat dbcp pool注意对应类变化
tomcat dbcp pool在tomcat 7 和tomcat8下的jar包有变化,相应包名也发生变化,对应类名有相应变化! tomcat的lib文件夹下会有jar包tomcat-dbcp.jar ...
- postman导入接口
给大家说一个poatman导入接口的好办法,平常要是想在postman上模拟接口,如果复杂的很难配,其实有一个很简单的方法: 现在我模拟一下百度搜索时历史记录的接口: 点击Copy as cUrl 然 ...
- 洛谷 P2330 [SCOI2005] 繁忙的都市 x
题目描述 城市C是一个非常繁忙的大都市,城市中的道路十分的拥挤,于是市长决定对其中的道路进行改造.城市C的道路是这样分布的:城市中有n个交叉路口,有些交叉路口之间有道路相连,两个交叉路口之间最多有一条 ...
- 使用idea上传项目到码云
首先,基本流程是这样的: 1.在码云生成SSH公钥 2.在码云创建项目 3.克隆项目到本地 4.在本地创建项目 5.搭建本地仓库,关联远程仓库 ...
- Spring Boot教程(十)异步方法测试
测试 测试代码如下: @Component public class AppRunner implements CommandLineRunner { private static final Log ...
- 使用GitHub(一):添加SSHkey
使用GitHub(一):添加SSHkey 本文简单介绍使用GitHub对代码进行版本控制,包括添加SSHkey.配置Git.使用Git创建版本库并在GitHub上进行管理,主要目的是对学习内容进行总结 ...
- 二进制方式安装mysql
下载官方打包好的rpm的集合 https://downloads.mysql.com/archives/get/file/mysql-5.7.20-1.el7.x86_64.rpm-bundle.ta ...
- eclipse导入工程
一般项目配置信息完全可直接导入,即import 如果缺失.project等文件,eclipse无法识别,则将工程拷贝到工作空间目录下,在eclipse中新建一个同名工程即可
- eclipse经常卡死
修改eclipse.ini 将启动内存,最小内存,最大内存都增大 eclipse是内存不够再去申请,直到有最大内存的 若上述方法不行则换eclipse eclipse有的版本是不稳定的,我用Ke ...