toj 3072 Train Order
来源:互联网 发布:匿名内部类java构造器 编辑:程序博客网 时间:2024/04/19 08:41
<center><span size="+2" style="">3072.</span> <span size="+2" style="color:blue;">Train Order</span> <hr /><span style="color:green;">Time Limit:</span> 1.0 Seconds <span style="color:green;">Memory Limit: </span>65536K<span style="color:green;">Total Runs: </span>435 <span style="color:green;">Accepted Runs: </span>244</center><hr /><span lang="en"></span><div id="problem">There is a railway station in PopPush City (See the picture below). All the trains arriving from A are numbered 1,2,3,...<em>N</em>. The station is dead-end, and some trains may stop here temporarily to let the behind trains pass by. Please note the trains cannot go backward, that is, once they enter the station, they cannot return to the direction A, and once they left the station to direction B, they cannot return the station too. <p></p><p align="center"><img src="http://acm.tju.edu.cn/acm/image/exam/1048_train.gif" alt="" /></p>Now your task is, given <em>N</em>, output all the possible sequence when all the trains left the station. Each sequence should be represented as a string containing only 1,2,3...<em>N</em>. And the string should be sorted lexicographically.<p></p><h3>Input</h3>The first line is an integer <em>T</em>, the number of test cases. Then <em>T</em> cases follows.<p>Each case contains only one number <em>N</em> in one line. You can assume 1 ≤ <em>N</em> ≤ 9.</p><p></p><h3>Output</h3>Output all the possible sequences for each test case. Each line contains one sequence.<p></p><h3>Sample Input</h3><tt></tt><pre>223
Sample Output
1221123132213231321#include<stdio.h>#include<algorithm>#include<stack>using namespace std;int mark[15];int a[15],b[15];int judge(int b[],int n){stack<int>s;int i,k=0;for(i=1;i<=n;i++) { s.push(i); if(i==b[k]) { while(!s.empty()&&b[k]==s.top()) { s.pop(); k++; }} } if(s.empty()) return 1;else return 0;}int main(){int T;int n;scanf("%d",&T);for(int i=0;i<=10;i++) a[i]=i+1;while(T--){scanf("%d",&n);sort(a,a+n);do{if(judge(a,n)){for(int i=0;i<n;i++) printf("%d",a[i]);printf("\n");}}while(next_permutation(a,a+n));}return 0;}
0 0
- toj 3072 Train Order
- toj 3072. Train Order
- TOJ 3859 Letter Order
- TOJ 1935.Symmetric Order
- toj3072 Train Order
- train
- train
- train
- train
- order
- ORDER
- Order
- TOJ 2976
- toj 3140
- toj 1153
- TOJ 1772
- TOJ 3250
- TOJ 3051
- ERP实施项目的计划阶段要点分析
- C/C++中相对路径与绝对路径以及斜杠与反斜杠的区别
- 关于Java交换两个对象的问题
- 修改ZigBee协调器内存大小
- php、asp 发起post请求
- toj 3072 Train Order
- OC 学习第六天_Block的使用
- 接口和抽象类的区别
- Linux 中mdelay() 与msleep()的区别
- 了解blocks基本语法
- 小问题的解决,小进步
- SPOJ 705 New Distinct Substrings (后缀数组)
- #1116 : 计算
- VC C/C++ 函数调用约定