思维体操: 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\ ...
随机推荐
- Linux下lazarus交叉编译 win32[win64]
环境 vmvare + deepin Linux64 + lazarus2.0.6 参考:https://wiki.freepascal.org/Cross_compiling_for_Win32_u ...
- js-点击tab按钮,同一页面显示不同的内容
效果: html: JS: css: .tabs-two{ .two{ display: inline-block; font-size:14px; height: 17px; font-weight ...
- C++ - 操作运算符
一.操作运算符 操作运算符:在C++中,编译器有能力将数据.对象和操作符共同组成表达式,解释为对全局或成员函数的调用 该全局或成员函数被称为操作符函数,程序员可以通过重定义函数操作符函数,来达到自己想 ...
- sh_06_女友的节日
sh_06_女友的节日 # 定义 holiday_name 字符串变量记录节日名称 holiday_name = "生日" # 如果是 情人节 应该 买玫瑰/看电影 if holi ...
- Jquery EasyUI tree 的异步加载(遍历指定文件夹,根据文件夹内的文件生成tree)
private void SMT(HttpContext context) { string SqlConnection82 = System.Configuration.ConfigurationM ...
- 快速找到oracle的alert日志
https://jingyan.baidu.com/article/f3ad7d0fe5d31309c3345b9b.html
- ES6 暂时性死区
在ES6中,声明变量新增了两个关键字:let命令和const命令 如果在区块中存在let或者const命令时,任何变量都必须在声明之前使用,无论是区块外部的全局变量或者是区块内部的变量: /* 区块外 ...
- Hibernate一级缓存之懒加载问题
Hibernate的懒加载: 当用到数据的时候才向数据库查询,这就是hibernate的懒加载特性. 目的,为提高程序执行效率. 查询操作:get()方法/load()方法 (1)get()方法,及时 ...
- 一元回归1_基础(python代码实现)
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003&u ...
- org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping clas
在Hibernate中使用annotation出现错误.如题目所示. HibernateSessionFactory类中: // private static Configuration co ...