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 ...
随机推荐
- PostgreSQL:安装
官网地址:https://www.postgresql.org/ 安装文件下载地址:http://www.enterprisedb.com/products-services-training/pgd ...
- MongoDB(一):安装
安装 从度娘上搜索MongoDB,找到官网地址:https://www.mongodb.com 找到下载中心地址:https://www.mongodb.com/download-center 我下载 ...
- node.js中使用node-schedule实现定时任务
摘要:有时我们需要在每天的固定时间执行某个脚本,或者在某个固定时间执行某个任务.NodeJS中的 node-schedule 可以很好的实现定时任务. 1.安装 npm install node-sc ...
- Regist
using (RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\Current ...
- [转] linux中pam模块
一.pam简介 Linux-PAM(linux可插入认证模块)是一套共享库,使本地系统管理员可以随意选择程序的认证方式. 换句话说,不用(重新编写)重新编译一个包含PAM功能的应用程序,就可以改变它使 ...
- 夺命雷公狗---DEDECMS----10dedecms双标签
双标签基本语法如下: {dede:标签名 参数名=“值” 参数名2=“值”...} 内容...... {/dede} 我们先来查看下手册,如下所示: 我们先来用一个channel的标签来做实例,因为c ...
- 几款python集成开发环境
以下软件的测试环境为ArchLinux64位系统.对软件的介绍很粗略,详细介绍参考官网. 1-名称:eric 官网:http://eric-ide.python-projects.org/ 特点:该软 ...
- 【crunch bang】 增加“菜单项”
[右键菜单]->[Settings]->[Openbox]->[GUI Menu Editor] 挑选合适的位置,增加[菜单项],编辑内容.
- SQL 基础语法(创建表空间、用户、并授予权限、数据的增删改查) --(学习笔记)[转]
--创建表空间 名:lyayzh_test create tablespace lyayzh_test --创建表数据文件 名:lyayzh_test_data.dbf 必须以dbf为后缀 dataf ...
- 三层架构中bll层把datatable转换为实体model的理解
看了很多人的项目,很多都是用到三层架构,其中BLL层中有一种将DataTable转换为实体的方法.一直没有明白为啥要这样做,今天特意去搜索了一下,如果没有答案我是准备提问,寻求解答了.还好找到一个相关 ...