【例题 6-2 UVA - 514】Rails
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
栈模拟一下就好。
每个输出段后面都有一个空行。
包括最后一个.
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n,a[N+10],bo[N+10];//bo = 1-> inque bo = 2->instack
stack <int> sta;
bool ok(int n)
{
while (!sta.empty()) sta.pop();
int now = 1;//inque first
for (int i = 1;i <= n;i++) bo[i] = 1;
for (int i = 1;i <= n;i++)
{
while (bo[a[i]]==1)
{
sta.push(now);
bo[now++] = 2;
}
if (sta.top()!=a[i]) return false;
sta.pop();
}
}
int main()
{
while (~scanf("%d",&n) && n)
{
while (scanf("%d",&a[1]) && a[1])
{
for (int i = 2;i <= n;i++) scanf("%d",&a[i]);
if (ok(n))
puts("Yes");
else
puts("No");
}
puts("");
}
return 0;
}
【例题 6-2 UVA - 514】Rails的更多相关文章
- UVA 514 - Rails ( 铁轨)
from my CSDN: https://blog.csdn.net/su_cicada/article/details/86939523 例题6-2 铁轨(Rails, ACM/ICPC CERC ...
- UVa 514 Rails(经典栈)
Rails There is a famous railway station in PopPush City. Country there is incredibly hilly. The st ...
- Uva - 514 - Rails
C是一个栈,每次先检查A的第一个元素是否满足,如果满足,直接进入B:再检查C中栈顶元素是否满足,如果满足,出栈进入B:前两步都不满足将A放入C栈中.循环到B满或者A,C中都不满足条件并且A空,第一种情 ...
- UVa 514 Rails(栈的应用)
题目链接: https://cn.vjudge.net/problem/UVA-514 /* 问题 输入猜测出栈顺序,如果可能输出Yes,否则输出No 解题思路 貌似没有直接可以判定的方法,紫书上给出 ...
- UVA ~ 514 ~ Rails (栈)
参考:https://blog.csdn.net/ZscDst/article/details/80266639 #include <iostream> #include <cstd ...
- UVA - 514 Rails(栈模拟)
题目: 给出一个序列,问将1,2,3,4……按从小到大的顺序入栈,能否得到给出的序列. 思路: 用stack模拟就可以了. 当前的cnt如果小于a[i],就将cnt入栈,否则就判断栈顶是不是和a[i] ...
- 铁轨(rails, ACM/ICPC CERC 1997,Uva 514)
铁轨(rails, ACM/ICPC CERC 1997,Uva 514) 题目描述 某城市有一个火车站,铁轨铺设如图所示.有n节车厢从A方向驶入车站,按进站顺序编号为1~n.你的任务是让它们按照某种 ...
- Rails,uva 514
题目:铁轨 题目链接:UVa514链接 题目描述: 某城市有一个火车站,有n节车厢从A方向驶入车站,按进站的顺序编号为1-n.你的任务是判断是否能让它们按照某种特定的顺序进入B方向的铁轨并驶入车站.例 ...
- UVa 514 (stack的使用) Rails
练习一下stack的使用,还有要注意一下输入的格式,看了好长时间没懂. //#define LOCAL #include <iostream> #include <cstdio> ...
随机推荐
- webgoat 7.1 实战指南
WSASP中文文档参考链接: http://www.owasp.org.cn/owasp-project/2017-owasp-top-10 OWASP Top 10 2017中文版V1.3http: ...
- amaze ui响应式辅助
amaze ui响应式辅助 响应式辅助 就是不同的显示屏幕,或者手机的横竖屏,你可以控制栏目的显影,还是挺有帮助的 视口大小 .am-[show|hide]-[sm|md|lg][-up|-down| ...
- System.GC.Collect();//垃圾回收,回收没有正常关闭的http连接
System.GC.Collect();//垃圾回收,回收没有正常关闭的http连接
- javafx DropShadow
public class EffectTest extends Application { DropShadow shadow = new DropShadow(); public static vo ...
- logout命令用于退出当前登录的Shell
logout命令用于退出当前登录的Shell
- 【Hello 2018 A】 Modular Exponentiation
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 当a<b的时候 a%b==a 显然2^n增长很快的. 当2^n>=1e8的时候,直接输出m就可以了 [代码] #incl ...
- Oracle中NVL、NVL2、DECODE函数的用法
DECODE函数的用法: DECODE(value,if1,then1,if2,then2,if3,then3,......,else),表示如果value的值等于if1时,DECODE函数的结果 ...
- 【D3 API 中文手冊】
[D3 API 中文手冊] 声明:本文仅供学习所用,未经作者同意严禁转载和演绎 <D3 API 中文手冊>是D3官方API文档的中文翻译. 始于2014-3-23日,基于VisualCre ...
- lighttpd启动不了,libssl.so.4&libcrypto.so.4 缺失
lighttd的出错日志在 log/out_lighttpd 里,当lighttd启动不了时候,这里文件中会说明原因. 今天的报错是 error while loading shared librar ...
- Atcoder At Beginner Contest 068 C - Cat Snuke and a Voyage
C - Cat Snuke and a Voyage Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem State ...