HDU_1022
题目:
![](http://acm.hdu.edu.cn/data/images/1022-1.jpg)
![](http://acm.hdu.edu.cn/data/images/1022-2.jpg)
![](http://acm.hdu.edu.cn/data/images/1022-3.jpg)
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.".
![](https://img2018.cnblogs.com/blog/1068222/201904/1068222-20190425151541353-828847099.png)
图一
图二
图三
#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的更多相关文章
随机推荐
- ie6 双边距问题
div 设置float和margin margin在float方向上会变成设置值的两倍 解决方法,加上css _display:inline
- 〈Android 群英传-神兵利器〉第7章一个的寂寞与一群人的狂欢
|---第7章一个的寂寞与一群人的狂欢 |---7.1如何解决问题 |---Chrome浏览器 |---Chrome开发者工具 |---Chrome插件(Json-Handle:Json格式化查看工具 ...
- opencv3.1+contrib的配置大总结(配置了两天,遇到问题无数)
开门见山的说:别用opencv3.0,这个版本添加扩展库不怎么好,能不能成功我不敢说,我是试了无数次都不行!!! 我的配置:W7+64位+opencv3.1+Cmake3.7.2 下载 下载什么的大家 ...
- windows phone, 应用最大内存
windows phone应用最大内存为150M,当app运行时所占内存超过150M时app会自动退出(VS debug时不容易捕捉到这个内存超出异常). [注]可通过配置增大最大内存
- 使用flash导出图集动画到unity
1.选中要导出的元件,元件所有动作要对齐,右键导出Sprite Sheet.. 2.设置如下 3.复制导出的png图片到unity,对图片进行网格裁剪,网格宽高在plist文件中:
- Virtualbox [The headers for the current running kernel were not found] (操作过程后还是失败,显示相同问题)
在笔记本安装Ubuntu11.04增强功能失败 引用 fuliang@fuliang-VirtualBox:~$ sudo /etc/init.d/vboxadd setup Removing exi ...
- 设计模式学习笔记(1)Iterator
Iterator 模式 public interface Iterator { public boolean hasNext(); public Object next(); } public int ...
- Away3D 学习笔记(一): 加载3DS格式的模型文件
加载外部的3DS文件分为两种: 1: 模型与贴图独立于程序的,也就是从外部的文件夹中读取 private function load3DSFile():Loader3D { loader = new ...
- DELPHI WM_CopyData 用法
unit Unit1; interface usesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, ...
- 写一个singleton
第一种:饱汉模式 public class SingleTon { private SingleTon(){ } //实例化放在静态代码块里可提高程序的执行效率,但也可能更占用空间 private f ...