杭电1022Train Problem I
2016-04-04 15:19
483 查看
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1022
题目:
Problem Description
As 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.
#include <iostream> #include <algorithm> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <stack> #include <map> #include <vector> #include <string> #define PI acos((double)-1) #define E exp(double(1)) #define N 1000000 using namespace std; int main (void) { int t,a,b,flag,c; string s,e,code; stack<int>sk; while(scanf("%d",&t) == 1 && t) { cin>>s>>e; flag=1; a=b=c=0; while(b<t) { if(s[a] == e[b]) { a++;b++; code[c++]=1; code[c++]=0; } else if(!sk.empty() && e[b] == sk.top()) { sk.pop();b++; code[c++]=0; } else if(a < t) { sk.push(s[a++]); code[c++]=1; } else { flag = 0; break; } } if(flag) { cout<<"Yes."<<endl; for(int i = 0;i< 2*t;i++) if(code[i]) cout<<"in"<<endl; else cout<<"out"<<endl; } else cout<<"No."<<endl; cout<<"FINISH"<<endl; while(!sk.empty()) sk.pop(); } return 0; }View Code
相关文章推荐
- A. Dreamoon and Stairs(Codeforces Round #272)
- QPainter 使用注意事项
- 杭电1021Fibonacci Again
- 解决sublimeText3无法安装插件有关问题 - There are no packages available for installation
- LeetCode Palindrome Pairs
- 服务器TIME_WAIT和CLOSE_WAIT详解和解决办法
- Tensorflow 官方版教程中文版
- 解决time_wait过多的问题
- 2016微软开发者大会 - 简洁收集
- 70. Climbing Stairs
- RAID各级别特性
- 学习笔记之RAID各级别特性
- wait()、notify()、notifyAll()
- 10013---Trail ~ Catalogs
- POJ 1273 USACO 93 Drainage Ditches 最大流
- 使用jacob将word转为pdf时报com.jacob.com.ComFailException: Invoke of: SaveAs ...
- 【BZOJ1660】【Usaco2006 Nov】Bad Hair Day 乱发节
- 造人论坛上关于人工智能的一些科幻想法
- http://blog.csdn.net/i_bruce/article/details/39555417
- 写Detail的接口