zoukankan      html  css  js  c++  java
  • cdoj 847 方老师与栈 火车进出战问题

    //其实我是不想写这题的,但是这题让我想起了我年轻的时候

    解法:直接模拟栈就好。

    //另外我年轻时候做的那题数据范围比较小,原理也不一样。

    //对于序列中的任何一个数其后面所有比它小的数应该是倒序的,因此对于任意三个数a,b,c(按顺序),若b<a c<a 则有b>c

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cmath>
     4 #include<algorithm>
     5 #include<cstring>
     6 #include<cstdlib>
     7 #include<queue>
     8 #include<vector>
     9 #include<map>
    10 #include<stack>
    11 #include<string>
    12 
    13 using namespace std;
    14 
    15 int n;
    16 int a[1000007];
    17 int b[1000007];
    18 int stk[1000007];
    19 int top=0;
    20 int nowb=0;
    21 
    22 int main(){
    23     scanf("%d",&n);
    24     for (int i=0;i<n;i++) scanf("%d",&a[i]);
    25     for (int i=0;i<n;i++) scanf("%d",&b[i]);
    26     for (int i=0;i<n;i++){
    27             stk[++top]=a[i];
    28             while (top>0 && stk[top]==b[nowb]){
    29                     top--;
    30                     nowb++;
    31             }
    32     }
    33     if (nowb==n)
    34         printf("Yes
    ");
    35     else
    36         printf("No
    ");
    37     return 0;
    38 }
    39 /*
    40 3
    41 3 2 1
    42 1 2 3
    43 
    44 4
    45 1 2 3 4
    46 3 1 2 4
    47 */
  • 相关阅读:
    导出 IIS 站点及配置
    redis
    mongo常用
    mongo分片集群
    mysql常用
    elk安装
    Oracle数据库迁移文档
    笔记
    ping 。sh
    光衰报警
  • 原文地址:https://www.cnblogs.com/baby-mouse/p/4455071.html
Copyright © 2011-2022 走看看