zoukankan      html  css  js  c++  java
  • 小明在工作

    Description

    小明的工作是负责记录饭堂中正在排队的人的信息 
    在他的工作中会有三种可能的事件发生: 
        1.编号为id的学生加入到队伍的最后面 
        2.排在最前面的学生打完饭离开了队伍 
        3.老板过来询问当前排在队伍前方第k个的学生的编号 
    由于每天的工作量太大(每天最多有100000个以上事件发生), 
    小明苦不堪言,让你写个程序帮他 

    Input

    输入的第一个数是正整数T,表明接下来有T组数据 
    每组数据的第一个数为正整数n,表示有n件事会发生 
    接下来有n行,每行分别表示上诉三种事件的其中一种,格式分别如下: 
    1 id 

    3 k 
    注意当队伍中已经没人的时候请忽略第2种事件,每组数据新开始的时候队伍中人数都为0

    Output

    对于给个第3种的事件,请输出第k个学生的编号, 
    如果队伍的人数小于k,输出“na li you zhe me duo ren”。

    Sample Input

    2 5 1 1 1 2 3 1 2 3 1 2 1 1 3 2

    Sample Output

    1 2 na li you zhe me duo ren

    HINT

    简单模拟,(每天最多有100000个以上事件发生),所以最多加这么多个人。

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 #include <string>
     5 #include <algorithm>
     6 using namespace std;
     7 int T, n;
     8 #define maxn 100010
     9 int a[maxn];
    10 int main(){
    11     scanf("%d", &T);
    12     while(T--){
    13         scanf("%d", &n);
    14         int first = 0, last = 0;
    15         int cnt;
    16         for(int i = 1; i <= n; i++){
    17             scanf("%d", &cnt);
    18             if(cnt == 1){
    19                 int id;
    20                 scanf("%d", &id);
    21                 a[last] = id;
    22                 last++;
    23             }
    24             else if(cnt == 2){
    25                 if(last != first) first++;
    26             }
    27             else if(cnt == 3){
    28                 int k;
    29                 scanf("%d", &k);
    30                 if(last - first < k) printf("na li you zhe me duo ren
    ");
    31                 else printf("%d
    ",a[first+k-1]);    
    32             }
    33         }
    34         
    35     }
    36     
    37     return 0;
    38 }
  • 相关阅读:
    cavans笔记
    input心得
    杂乱的笔记
    CSS学习目录
    CSS3四个自适应关键字——fill-available、max-content、min-content、fit-content
    闭包
    0..0 小白
    Scrum
    Git与GitHub
    博客1
  • 原文地址:https://www.cnblogs.com/titicia/p/4341979.html
Copyright © 2011-2022 走看看