hdu-1022-Train Problem I
来源:互联网 发布:js array键值对 编辑:程序博客网 时间:2024/06/16 22:09
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.
3 123 3213 123 312
Yes.inininoutoutoutFINISHNo.FINISH 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.".
Hint
#include <iostream>#include <stack>#include <queue>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int n; while(cin>>n && n) { getchar(); char str[15],mod[15]; scanf("%s%*c%s%*c",str,mod); stack<char> st; while(!st.empty()) st.pop(); int i, j; bool step[100]; int k=0,sum=0; for(i=0,j=0 ;i<=n && j<n && sum <= 9 ;i++) { st.push(str[i]); step[k++]=1; sum++; while(!st.empty() && st.top()==mod[j]) { st.pop(); step[k++]=0; j++; sum--; } } if(st.empty()&&( i>n || j>=n )) { cout<<"Yes."<<endl; for(i=0 ; i<k ; i++) { if(step[i]) { cout<<"in"<<endl; } else { cout<<"out"<<endl; } } cout<<"FINISH"<<endl; } else { cout<<"No."<<endl<<"FINISH"<<endl; } } return 0;}
阅读全文
0 0
- HDU 1022 Train Problem I
- HDU-1022 Train Problem I
- HDU 1022 Train Problem I
- HDU 1022 ( Train Problem I )
- HDU 1022 Train Problem I
- HDU 1022 Train Problem I
- Hdu 1022 - Train Problem I
- HDU-1022:Train Problem I
- hdu 1022 Train Problem I
- hdu 1022 Train Problem I
- hdu-Train Problem I-1022
- hdu 1022 Train Problem I
- hdu 1022 Train Problem I
- hdu 1022 Train Problem I
- HDU 1022 Train Problem I
- hdu 1022 Train Problem I
- hdu 1022 Train Problem I
- HDU 1022Train Problem I
- JUnit4时间(超时)测试实例
- 【Android】解决SurfaceView 会闪 露出背景内容的问题
- Maven入门学习
- 栈的创建 以及基本操作出栈 入栈,判空
- PLSQL 中的存储过程和函数简单使用
- hdu-1022-Train Problem I
- shiro的多数据源和认证策略
- Caffe源码阅读笔记
- struts2配置文件常用配置
- React Native入门(五)之使用输入框TextInput,按钮Button搭建登录界面
- M
- r-cnn系列代码编译及解读(3)
- (ubuntu)下apache2 有关的系统文件的路径和说明
- LightOJ1236