思维体操: 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 连接mssqlserver
1 . 从https://www.freetds.org/ 下载驱动源文件 2. 参照 https://www.freetds.org/userguide/config.htm 内容编译 3. 启动l ...
- Selenium 定位一组元素
到目前为止,我们已经知道了怎么去定位一个元素,有时候我们需要获取页面上的多个元素,该怎么办呢?难道还一个一个地去定位,那也太lower了吧. webdriver提供了定位一组元素的方法,跟前面讲的那八 ...
- (48)LINUX应用编程和网络编程之三Linux获取系统信息
3.3.1.关于时间的概念 3.3.1.1.GMT时间 (1)GMT是格林尼治时间,也就是格林尼治地区的当地之间. (2)GMT时间的意义?[用格林尼治的当地时间作为全球国际时间],用以描述全球性的事 ...
- java复制项目中的补丁,完整的包路径
package com.bytter.audit.iface.util; import java.io.BufferedInputStream; import java.io.BufferedOutp ...
- Oracle报Ora01522
应用服务报错截图 数据库后台日志报错截图 从日志分析应该是回滚异常造成表空间无法使用回滚段,而回滚涉及的表空间为undo表空间 尝试新建UNDO表空间,再将UNDO_TABLESPACE切换到新建的U ...
- What's the difference between HEAD^ and HEAD~ in Git?
https://stackoverflow.com/questions/2221658/whats-the-difference-between-head-and-head-in-git Rules ...
- jquery自动播放音频文件
使用jquery自动播放音频文件 <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- gsensor架构和原理分析【转】
本文转载自:http://blog.csdn.net/u012296694/article/details/48055491 本文主要描述了在android2.3平台G-sensor相关软硬件的体系架 ...
- IE浏览器中图片路径正确< img ... />标签不显示图片
如下图所示,下面的html要去加载上面的jpg图片: 代码如下: <img src="luzhanshi1.jpg" alt="图片加载失败"> 使 ...
- 那些年我们经历的BT面试题
初入职场面试的我到处碰壁,以下是我个人对几道面试题的小总结: 1.一列数字的规则如下:1,1,2,3,5,8,13,21, 34........ 求第30位数字是多少,用递规和非递归两种方法算法实现. ...