Train Problem I 分类: HDU 2015-06-26 11:27 10人阅读 评论(0) 收藏
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25029 Accepted Submission(s): 9445
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.
FINISH/*
模拟题,利用栈,最先出栈的在最前,不断的进栈,同时比较栈头与出栈的元素是不是相同的,
如果相同则出栈,最后如果还有剩余元素,则不符合
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack> using namespace std; const int Max=1100000; char IN[15];
char OUT[15];
string str[110];
int main()
{
int n;
while(~scanf("%d %s %s",&n,IN,OUT))
{
int top=0;
stack<char>a;
int i=0,j=0;
while(i<n&&j<n)
{
if(a.empty()||a.top()!=OUT[j])
{
a.push(IN[i++]);
str[top++]="in";
}
else
{
a.pop();
j++;
str[top++]="out";
}
}
while(j<n&&!a.empty()&&a.top()==OUT[j])
{
a.pop();
j++;
str[top++]="out";
}
if(a.empty())//判断是否符合
{
cout<<"Yes."<<endl;
for(int i=0;i<top;i++)
{
cout<<str[i]<<endl;
}
cout<<"FINISH"<<endl;
}
else
{
cout<<"No."<<endl<<"FINISH"<<endl;
}
} return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Train Problem I 分类: HDU 2015-06-26 11:27 10人阅读 评论(0) 收藏的更多相关文章
- Retinex系列之McCann99 Retinex 分类: 图像处理 Matlab 2014-12-03 11:27 585人阅读 评论(0) 收藏
一.McCann99 Retinex McCann99利用金字塔模型建立对图像的多分辨率描述,自顶向下逐层迭代,提高增强效率.对输入图像的长宽有 严格的限制,要求可表示成 ,且 ,. 上述限制来源于金 ...
- short-path problem (Spfa) 分类: ACM TYPE 2014-09-02 00:30 103人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include <queue> #i ...
- short-path problem (Floyd) 分类: ACM TYPE 2014-09-01 23:58 100人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...
- short-path problem (Dijkstra) 分类: ACM TYPE 2014-09-01 23:51 111人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...
- 百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET 2015-01-12 11:18 346人阅读 评论(0) 收藏
在百度编辑器示例代码基础上进行了修改,封装成类库,只需简单配置即可使用. 完整demo下载 版权声明:本文为博主原创文章,未经博主允许不得转载.
- Crashing Robots 分类: POJ 2015-06-29 11:44 10人阅读 评论(0) 收藏
Crashing Robots Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8340 Accepted: 3607 D ...
- Least Common Ancestors 分类: ACM TYPE 2014-10-19 11:24 84人阅读 评论(0) 收藏
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- 二分图匹配(KM算法)n^4 分类: ACM TYPE 2014-10-04 11:36 88人阅读 评论(0) 收藏
#include <iostream> #include<cstring> #include<cstdio> #include<cmath> #incl ...
- Segment Tree with Lazy 分类: ACM TYPE 2014-08-29 11:28 134人阅读 评论(0) 收藏
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; stru ...
随机推荐
- 不等高cell搭建(二)
一.commentView模块搭建 commentView样式分为两种 1.xib搭建界面 1.1 因为评论的样式大体上一样,我们可以用同一个xib来处理 1.2 最热评论 用 ...
- editplus3运行Python程序
editplus3是一款不错的编辑器,他可以编译,运行java,php等各种程序,现把他运行Python程序的方法贴出来,首先得安装python,然后打开editplug3,工具——配置用户工具——组 ...
- prezi破解教程
http://www.joenchen.com/archives/998 http://www.joenchen.com/archives/945 Prezi Desktop 4.7.5免注册无时间限 ...
- c#读取INI文件类
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;na ...
- :nth-child()和:nth-of-type(n)区别
ele:nth-child(n) 父元素下第n个元素且这个元素为ele ele:nth-of-type(n) 指父元素下第n个ele元素
- 夺命雷公狗—angularjs—15—内置封装好的计时器$interval和$timeout
这里其实和js源生的效果是一样的,但是源生的在angularjs里面不能直接正常执行代码如下所示: <!DOCTYPE html> <html lang="en" ...
- libSVM 简易使用手册
关于SVM的基础理论知识,可以google这篇文章<SVM的八股简介>,讲解得生动有趣,是入门的极好教材.作为拿来主义者,我更关心怎么用SVM,因此瞄上了台湾林智仁教授提供的libSVM. ...
- 关于更改MYECLIPSE JS 代码背景颜色
白色的背景,看花了眼,你想改一下编辑器的背景颜色,移步这里就可以了. 这时你高兴的打开编辑器,发现颜色确实变了,但是当你打开有JS的JSP时,你碉堡了,发现JS的背景颜色还是默认的, 看着让人纠结,好 ...
- less文件的样式无法生效的一个原因,通过WEB浏览器访问服务器less文件地址返回404错误
有一种情况容易导致less文件的样式无法生效,就是部分服务器(以IIS居多)会对未知后缀的文件返回404,导致无法正常读取.less文件.解决方案是在服务器中为.less文件配置MIME值为text/ ...
- Openstack的删除错误网桥,虚拟网络
在实验openstack的各种网络模式时,可能会产生一些错误的网络指向,需要删除那些网桥. 执行前 [root@node-9 ~]# ifconfig br40 Link encap:Ethernet ...