POJ 1363 Rails(栈)
题目代号:POJ 1363
题目链接:http://poj.org/problem?id=1363
题目原题:
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 34585 | Accepted: 13434 |
Description

The local tradition is that every train arriving from the direction A continues in the direction B with coaches reorganized in some way. Assume that the train arriving from the direction A has N <= 1000 coaches numbered in increasing order 1, 2, ..., N. The chief for train reorganizations must know whether it is possible to marshal coaches continuing in the direction B so that their order will be a1, a2, ..., aN. Help him and write a program that decides whether it is possible to get the required order of coaches. You can assume that single coaches can be disconnected from the train before they enter the station and that they can move themselves until they are on the track in the direction B. You can also suppose that at any time there can be located as many coaches as necessary in the station. But once a coach has entered the station it cannot return to the track in the direction A and also once it has left the station in the direction B it cannot return back to the station.
Input
The last block consists of just one line containing 0.
Output
Sample Input
5
1 2 3 4 5
5 4 1 2 3
0
6
6 5 4 3 2 1
0
0
Sample Output
Yes
No Yes 通过代码:
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <fstream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define For(i,n,a) for(int i=n; i>=a; --i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define Fo(i,n,a) for(int i=n; i>a ;--i)
typedef long long LL;
typedef unsigned long long ULL; int a[],vect[],queu[]; int main()
{
for(int i=;i<=;i++)queu[i]=i;
int n,s;
while(cin>>n,n)
{
while(cin>>s,s)
{
bool flag=true;
int top=,pop=,ans=;
a[]=s;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
while(ans<=n)
{
if(pop<=n)
{
if(a[ans]>=queu[pop])vect[++top]=queu[pop++];
}
if(top)
{
if(a[ans]==vect[top])ans++,top--;
else if(a[ans]<vect[top]){flag=false;break;}
}
}
if(flag)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
cout<<endl;
}
return ;
}
POJ 1363 Rails(栈)的更多相关文章
- POJ 1363 Rails(栈)
思路:将出车站的顺序存入数组train,由于入车站的顺序是固定的,为1~N,所以用P表示进站的车,初始为1. 接下来举例说明吧: 原来入站顺序: 1 2 3 4 5 读入的出战顺序: 3 4 2 ...
- poj 1363 Rails in PopPush City &&【求堆栈中合法出栈顺序次数】
问题如下: 问题 B: Rails 时间限制: Sec 内存限制: MB 提交: 解决: [提交][状态][讨论版] 题目描述 There is a famous railway station in ...
- poj 1363 Rails (【栈的应用】 刘汝佳的写法 *学习)
Rails Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25964 Accepted: 10199 Descripti ...
- poj 1363 Rails 解题报告
题目链接:http://poj.org/problem?id=1363 题意:有一列火车,车厢编号为1-n,从A方向进站,向B方向出站.现在进站顺序确定,给出一个出站的顺序,判断出站顺序是否合理. 实 ...
- OpenJudg / Poj 1363 Rails
1.链接: http://poj.org/problem?id=1363 http://bailian.openjudge.cn/practice/1363 2.题目: Rails Time Limi ...
- POJ 1363 Rails
Rails Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21728 Accepted: 8703 Descriptio ...
- 【栈】 poj 1363
poj1363,这道题是数据结构与算法中的经典问题,给定一组进栈顺序,问栈有多少种出去的顺序. #include<stdio.h> #include <stack> #incl ...
- poj 1363 火车进站 (栈的应用)
Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...
- Poj 3250 单调栈
1.Poj 3250 Bad Hair Day 2.链接:http://poj.org/problem?id=3250 3.总结:单调栈 题意:n头牛,当i>j,j在i的右边并且i与j之间的所 ...
随机推荐
- C语言第八周编程作业
这个作业属于哪个课程 C语言程序设计 这个作业要求在哪 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/hom ...
- 第二周JAVA总结
学海无涯,在学习这件事情上得用点心了
- GCC 编译参数
-s 这个参数会把符号表从最终的可执行文件中删除.没有符号表,你就不能用gdb调试了,但是程序会更小 -O0 不做任何优化,这是默认的编译选项 -c 只编译不链接,产生.o文件,就是obj文件,不产生 ...
- [转帖]linux screen 命令详解,xshell关掉窗口或者断开连接,查看断开前执行的命令
linux screen 命令详解,xshell关掉窗口或者断开连接,查看断开前执行的命令 https://binwaer.com/post/12.html yun install -y screen ...
- How to attach multiple files in the Send Mail Task in SSIS
Let’s say you need to create a SSIS package that creates 2 files and emails the files to someone. Yo ...
- Hibernate-Criteria学习笔记
hibernate_jpa注解 目前最新版的hibernate,5.2,底层整合了jpa,用idea的hibernate工具生成实体时,实体包含了注解的配置文件,缺一不可 如,用户类实体,生成之后是这 ...
- git 中 HEAD detached from 802e836
head指针处于游离状态,需要建立一个分支然后将它合并到master分支,最后删除那个临时分支即可. 详情参见:https://www.jianshu.com/p/fdd3c2d020d7
- 【React 8/100】 React路由
React路由 React路由介绍 现代的前端应用大多数是SPA(单页应用程序),也就是只有一个HTML页面的应用程序.因为它的用户体验更好.对服务器压力更小,所以更受欢迎.为了有效的使用单个页面来管 ...
- 关于使用iframe的父子页面进行简单的相互传值
当一个页面使用了iframe作为嵌套时,如何想要将父页面的数据传给iframe子页面,那iframe所指向的呢个子页面是怎么获取呢,又或者子页面的数据要给父页面使用,那么父页面又如何获取子页面的数据呢 ...
- Java实现文件上传-按钮弹出上传页面
转自: https://blessht.iteye.com/blog/1405057 最近自己在做一个小系统玩的时候涉及到了文件的上传,于是在网上找到Java上传文件的方案,最后确定使用common- ...