zoukankan      html  css  js  c++  java
  • T3186 队列练习2 codevs

    http://codevs.cn/problem/3186/

    题目描述 Description

    (此题与队列练习1相比改了2处:1加强了数据 2不保证队空时不会出队)
    给定一个队列(初始为空),只有两种操作入队和出队,现给出这些操作请
    输出最终的队头元素。 操作解释:1表示入队,2表示出队

    输入描述 Input Description

    N(操作个数)
    N个操作(如果是入队则后面还会有一个入队元素)
    具体见样例(输入保证队空时不会出队)

    输出描述 Output Description

    最终队头元素,若最终队空,或队空时有出队操作,输出”impossible!”(不含引号)

    样例输入 Sample Input

    3
    1 2
    2
    2

    样例输出 Sample Output

    impossible!

    数据范围及提示 Data Size & Hint

    对于100%的数据  N≤100000 元素均为正整数且小于等于10^8

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5  
     6 using namespace std;
     7 
     8 int N,m,tail,head;
     9 int a[100000+15];
    10  
    11 int main()
    12 {
    13     cin>>N;
    14     for(int i=1;i<=N;i++)
    15     {
    16         cin>>m;        
    17         if(m==1)                
    18             cin>>a[++tail];            
    19         if(m==2)        
    20         {        
    21             head++;            
    22             if(head-1==tail)        
    23             {    
    24                 cout<<"impossible!";
    25                 return 0;
    26             }    
    27         }
    28     }
    29     if(tail-head==0)
    30         cout<<"impossible!";
    31     else
    32         cout<<a[head+1];
    33     return 0;
    34 
    35 }

     

    ——每当你想要放弃的时候,就想想是为了什么才一路坚持到现在。
  • 相关阅读:
    1月5日学习记录||1月8日学习
    1.1学习记录|1.2日学习记录|1.3日
    RNA-seq数据为什么要去噪
    12.16日学习记录
    12.15学习记录
    transformer和bert简要学习
    关系抽取学习
    12.14周六学习记录
    12.5日学习记录
    12.4周三学习记录
  • 原文地址:https://www.cnblogs.com/Shy-key/p/6371734.html
Copyright © 2011-2022 走看看