练习一下stack的使用,还有要注意一下输入的格式,看了好长时间没懂。

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
using namespace std; const int maxn = + ;
int n, target[maxn]; int main(void)
{
#ifdef LOCAL
freopen("514in.txt", "r", stdin);
#endif while(scanf("%d", &n) == && n)
{
while(scanf("%d", &target[]) == && target[])
{
for(int i = ; i <= n; ++i) scanf("%d", &target[i]);
stack<int> s;
int A = , B = ;
int ok = ;
while(B <= n)
{
if(A == target[B]) { A++; B++; }
else if(!s.empty() && s.top() == target[B]) { s.pop(); B++; }
else if(A <= n) s.push(A++);
else { ok = ; break; }
}
printf("%s\n", ok ? "Yes" : "No");
}
printf("\n");
} return ;
}

代码君

UVa 514 (stack的使用) Rails的更多相关文章

  1. 铁轨(rails, ACM/ICPC CERC 1997,Uva 514)

    铁轨(rails, ACM/ICPC CERC 1997,Uva 514) 题目描述 某城市有一个火车站,铁轨铺设如图所示.有n节车厢从A方向驶入车站,按进站顺序编号为1~n.你的任务是让它们按照某种 ...

  2. UVA 514 - Rails ( 铁轨)

    from my CSDN: https://blog.csdn.net/su_cicada/article/details/86939523 例题6-2 铁轨(Rails, ACM/ICPC CERC ...

  3. UVa 514 Rails(经典栈)

     Rails  There is a famous railway station in PopPush City. Country there is incredibly hilly. The st ...

  4. Rails,uva 514

    题目:铁轨 题目链接:UVa514链接 题目描述: 某城市有一个火车站,有n节车厢从A方向驶入车站,按进站的顺序编号为1-n.你的任务是判断是否能让它们按照某种特定的顺序进入B方向的铁轨并驶入车站.例 ...

  5. Uva - 514 - Rails

    C是一个栈,每次先检查A的第一个元素是否满足,如果满足,直接进入B:再检查C中栈顶元素是否满足,如果满足,出栈进入B:前两步都不满足将A放入C栈中.循环到B满或者A,C中都不满足条件并且A空,第一种情 ...

  6. UVa 514 Rails(栈的应用)

    题目链接: https://cn.vjudge.net/problem/UVA-514 /* 问题 输入猜测出栈顺序,如果可能输出Yes,否则输出No 解题思路 貌似没有直接可以判定的方法,紫书上给出 ...

  7. 【紫书】Rails UVA - 514 栈

    题意:判断出栈顺序是否合法 题解:两个指针,A指向入栈序列,B指向出栈. 的分三种情况:if     1.A==B :直接入栈加出栈即可A++,B++ else 2.和栈顶相同,直接出栈A==stac ...

  8. UVA ~ 514 ~ Rails (栈)

    参考:https://blog.csdn.net/ZscDst/article/details/80266639 #include <iostream> #include <cstd ...

  9. Rails UVA - 514(栈)

    题目链接:https://vjudge.net/problem/UVA-514 题目大意:右边的火车经过中间的收费站到左边,右边火车进站的秩序是1~n   判断是否能以题中是所给的次序通过 思路:很明 ...

随机推荐

  1. SQL TRY CATCH

    begin try select 1/0end trybegin catch select error_number() as 'number', error_line() as 'line', er ...

  2. javascript设计模式--中介者模式(Mediator)

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. chrome 网络面板

    Chrome Timeline的指标说明:Blocked.Connect.Send.Wait.Receive Blocked time includes any pre-processing time ...

  4. WCF Service的Restfull风格

    怎样构建? •您需要什么样的资源? •将使用哪些 URI 表示这些资源? •每个 URI 将支持统一接口的哪些部件(HTTP 动词)?    URI的处理   •UriTemplate –System ...

  5. Java日志记录的事儿

    一.java日志组件 1.common-logging common-logging是apache提供的一个通用的日志接口.用户可以自由选择第三方的日志组件作为具体实现,像log4j,或者jdk自带的 ...

  6. cf div2 234 D

    D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. 【剑指offer】题目38 数字在排序数组中出现的次数

    思路: 应该是用二分查找分别找到该数字第一次和最后一次出现的位置,相减即可.O(logn) int findLeft(int a[], int n, int num) { , r = n - ; wh ...

  8. tomcat 跨域

    http://www.360doc.com/content/14/0920/14/7909375_411017244.shtml http://www.tuicool.com/articles/Znq ...

  9. HashMap的key装换成List

    Map<String,Object> map = new HashMap<String,Object>(); map.put("a","32332 ...

  10. 2013 ACM/ICPC Asia Regional Changsha Online G Goldbach

    比赛的时候,被题目误导了,题目最后说结果可能很大,要取模,那时就想直接求会TLE的!!! 赛后才知道,坑啊………… 代码如下: #include<iostream> #include< ...