0%

1363 — Rails

2018年4月11日 下午3:54

题目:

1363 — Rails

解析:

POJ1363 Rails【stack】【栈】 - CSDN博客

坑:

  1. 一边放入一边判断那里我们有真实的去在纸上模拟各种情况,只是知道个大概,然后就动手做。
  2. 由于没有仔细的认真的分析,最后遇到问题也不停下来分析
  3. 总之,急于求成!!!!不踏实
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    #include <stdio.h>
    #include <stack>
    #include <queue>

    int main(){
    int n = 0;
    int num;

    scanf("%d",&n);
    while(n){
    scanf("%d",&num);
    while(num != 0){
    //初始化
    std::stack<int> S;
    std::queue<int> Q;

    Q.push(num);
    //放到Q中
    for(int i = 2; i <= n ;i++){//第一个已经方进入了
    scanf("%d",&num);
    Q.push(num);
    }
    //一边放入边判断
    for(int i = 1; i <= n ;i++){
    S.push(i);
    // while(Q.front()==S.top()){//这里是while,检查了半个小时!
    while(!S.empty() && Q.front()==S.top()){//这里少了判空,并且判空一定要放在前面
    Q.pop();
    S.pop();
    }
    }
    if(S.empty()){
    printf("Yes\n");
    }
    else{
    printf("No\n");
    }

    scanf("%d",&num);
    }

    printf("\n");
    scanf("%d",&n);
    }
    return 0;
    }