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): 21736 Accepted Submission(s): 8232
the new term comes, the Ignatius Train Station is very busy nowadays. A
lot of student want to get back to school by train(because the trains
in the Ignatius Train Station is the fastest all over the world ^v^).
But here comes 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.



input contains several test cases. Each test case consists of an
integer, the number of trains, and two strings, the order of the trains
come in:O1, and the order of the trains leave:O2. The input is
terminated by the end of file. More details in the Sample Input.
output contains a string "No." if you can't exchange O2 to O1, or you
should output a line contains "Yes.", and then output your way in
exchanging the order(you should output "in" for a train getting into the
railway, and "out" 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 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 <iostream>
- #include <cstdio>
- #include <math.h>
- #include <string.h>
- #include <algorithm>
- #include <queue>
- #include <stack>
- using namespace std;
- int main()
- {
- int n;
- int i, j, k;
- char s[1000], t[1000];
- char dd, ff;
- char map[1000][5]; int e=0;
- while(scanf("%d", &n)!=EOF)
- {
- stack<char>q;
- stack<char>p;
- memset(map, '\0', sizeof(map));
- scanf("%s", s);
- scanf("%s", t);
- for(j=n-1; j>=0; j--)
- {
- p.push(t[j]);
- }
- e=0;
- for(i=0; i<n; i++)
- {
- q.push(s[i]);
- //cout<<s[i]<<"*"<<endl;
- strcat(map[e++], "in");
- dd=q.top(); ff=p.top();
- while( dd==ff && !q.empty() && !p.empty() )
- {
- strcpy(map[e++], "out");
- q.pop();
- if(!q.empty()) dd=q.top();
- p.pop();
- if(!p.empty()) ff=p.top();
- }
- }
- if(q.empty() && p.empty() )
- {
- cout<<"Yes.\n";
- for(k=0; k<e; k++)
- {
- cout<<map[k]<<endl;
- }
- }
- else
- {
- cout<<"No.\n";
- }
- cout<<"FINISH\n";
- }
- return 0;
- }
HDU 1022 之 Train Problem I的更多相关文章
- HDU——1023 Train Problem II
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU 1022 Train Problem I(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1022 Train Problem I【模拟出入栈】
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Hdu 1022 Train Problem I 栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022.Train Problem I【栈的应用】【8月19】
Train Problem I Problem Description As the new term comes, the Ignatius Train Station is very busy n ...
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022:Train Problem I(数据结构,栈,递归,dfs)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- cf711E ZS and The Birthday Paradox
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that g ...
- Linux(9):期中架构(1)--- 集群构架 & 备份服务
01. 了解集群架构服务器组成 基本架构组成:(用于让用户进行访问) # 前端服务部分: 1)顾客-用户 是一个访问者,请求访问网站页面 2)保安-防火墙设备 对访问架构用户进行策略控制,正常访问网站 ...
- 济南学习 Day 5 T2 晚
等比数列(sequence) [题目描述] 判断一个数列是否为等比数列. 等比数列的定义为能被表示成a,aq,aq^2,aq^3...的数列,其中a和q不等于0. [输入说明] 输入文件的第一行有一个 ...
- delphi使用IdHTTP模拟提交页面方法总结
http://blog.csdn.net/lxdcyh/article/details/3986800 1.拖入TIdHTTP控件,HandleRedirect设为True,否则可能会出现HTTP 3 ...
- Google解决跨域
1.添加 --disable-web-security --user-data-dir=D:\tmp 2.在D的根目录新建tmp文件夹
- Iass、Pass、SasS三种云服务区别?
Iass.Pass.SasS三种云服务区别 我们可以把云计算理解成一栋大楼,而这栋楼又可以分为顶楼.中间.低层三大块.那么我们就可以把Iass(基础设施).Pass(平台).Sass(软件)理解成这栋 ...
- vue之监听事件
一.v-on 可以用 v-on 指令监听 DOM 事件,并在触发时运行一些 JavaScript 代码. 简写形式 用@代替 v-on: <button v-on:click="co ...
- [bzoj1110][POI2007]砝码Odw_贪心
bzoj-1110 POI-2007 砝码Odw 参考博客:http://hzwer.com/4761.html 题目大意:在byteotian公司搬家的时候,他们发现他们的大量的精密砝码的搬运是一件 ...
- P1536 村村通 洛谷
https://www.luogu.org/problem/show?pid=1536 题目描述 某市调查城镇交通状况,得到现有城镇道路统计表.表中列出了每条道路直接连通的城镇.市政府“村村通工程”的 ...
- luogu P1476 休息中的小呆
题目描述 当大家在考场中接受考验(折磨?)的时候,小呆正在悠闲(欠扁)地玩一个叫“最初梦想”的游戏.游戏描述的是一个叫pass的有志少年在不同的时空穿越对抗传说中的大魔王chinesesonic的故事 ...