HDU_1022
题目:



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 <stack>
#include <string>
#include <bits/stdc++.h>
using namespace std; #define IN 1
#define OUT 0
string a,b;
#define MAX_NUM 100100 int sep[MAX_NUM]; int main(int argc, char const *argv[])
{
int n;
while(cin >> n >> a >> b){
stack<char> s;
int i = , j = , k = ;
s.push(a[]);
sep[k++] = IN;
while(i < n && j < n){
if(s.size() != && s.top() == b[j]){
j++;
s.pop();
sep[k++] = OUT;
}else{
s.push(a[++i]);
sep[k++] = IN;
}
}
if(i == n){//如果i==n表示栈顶元素不等于序列2当前元素,且序列1中元素都已经入过栈,判断不能得到序列2一样的答案。
cout << "No." << endl;
}else{
cout << "Yes." << endl;
for (int i = ; i < k; ++i)
{
if(sep[i]){
cout << "in" << endl;
}
else{
cout << "out" << endl;
}
}
}
cout << "FINISH" << endl;
}
return ;
}
HDU_1022的更多相关文章
随机推荐
- aix-syslog
收集网络内路由器的日志信息,同时把本地日志信息与路由器信息分开. /etc/syslog.conf我写成: ## 本地日志处理 *.notice;*.err;*.warn<tab>;< ...
- ldap快速配置
1.[yum lamp环境] yum -y install httpd httpd-devel mysql mysql-server mysql-devel php php-mysql php-co ...
- 问题:ClientIDMode属性;结果:ASP.NET 4.0的ClientIDMode属性
ASP.NET 4.0的ClientIDMode属性 时光流逝,我们心爱的ASP.NET也步入了4.0的时代,微软在ASP.NET 4.0中对很多特性做了修改.比如我将要讨论的控件ID机制就是其中之一 ...
- 你该知道的 TValue
你该知道的 TValue Represents a lightweight version of the Variant type. TValue is a data structure that c ...
- xe DateTimePicker.Date bug
xe6 bug xe7 ok DateTimePicker1->DateTime.DateString(); DateTimePicker1->DateTime.DateTimeStrin ...
- word 2013 自动保存太慢,下面读条起码3分钟
该问题有可能是应用干扰或者安全设置问题导致的. 建议您尝试以下方法: 方法一: 尝试使用干净启动来暂时禁用计算机启动时所加载的第三方程序来进一步做测试: 如何在Windows 中执行干净启动步骤 具体 ...
- mysql 自动执行事件
首先配置mysql的配置文件my.ini, 加上event_scheduler = 1 开启自动执行事件配置 demo drop event event_test; CREATE EVENT ev ...
- 机器学习入门-DBSCAN聚类算法
DBSCAN 聚类算法又称为密度聚类,是一种不断发张下线而不断扩张的算法,主要的参数是半径r和k值 DBSCAN的几个概念: 核心对象:某个点的密度达到算法设定的阈值则其为核心点,核心点的意思就是一个 ...
- 机器学习入门-概率阈值的逻辑回归对准确度和召回率的影响 lr.predict_proba(获得预测样本的概率值)
1.lr.predict_proba(under_text_x) 获得的是正负的概率值 在sklearn逻辑回归的计算过程中,使用的是大于0.5的是正值,小于0.5的是负值,我们使用使用不同的概率结 ...
- vue基础——模板语法
模板语法介绍 Vue.js使用了基于HTML的模板语法,允许开发者声明式地将dom绑定至底层Vue实例的数据.所有Vue.js的模板都是合法的HTML,所以能被遵循规范的浏览器和HTML解析器解析. ...