zoukankan      html  css  js  c++  java
  • 数据结构 机场管理程序

    Description

    给出机场中飞机及跑道的编号和多个操作,对于每个查询操作,输出查询结果。

    Input

    第一行是一个整数,代表数据组数。每组数据第 一行为两个整数n(1<=n<=10)、m(1<=m<=1000),分别代表机场跑道数量(实际上就是队列的个数)

    和操作数量 (实质就是对队列操作的种类)。接下来m行每行开始是一个整数p,代表操作种类。操作种类p有如下几种:
    1) 0 x k:代表编号为x的跑道起飞了k架飞机,并查询起飞的顺序。航班号示例: CA1544、MU5341、CZ3869。
    2) 1 x y:编号为x的飞机降落在了编号为y的跑道。
    3) 2 x:查询编号为x的跑道有多少飞机。

    Output

    每组第一行输出数据组数,然后对于每个q为0和q为2的操作输出查询的值,q为0时输出航班号,每个航班号一行,格式见样例。

    Sample Input

    1
    2 3
    1 CA1544 1
    0 1 1
    2 2

    Sample Output

    Case #1 :
    CA1544
    0

    HINT

    考察知识点:多个队列, 时间复杂度O(n),空间复杂度O(n)


    Append Code

    析:用一个队列组来代表不同的飞机场,剩下的就是模拟了。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    #include <cmath>
    #include <stack>
    #include <list>
    #define ALL(x) x.begin(),x.end()
    #define INS(x) inserter(x,x.begin())
    #define frer freopen("in.txt", "r", stdin)
    #define frew freopen("out.txt", "w", stdout)
    using namespace std;
     
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f;
    const double PI = acos(-1.0);
    const double eps = 1e-8;
    const int maxn = 1e5 + 5;
    const int mod = 1e9 + 7;
    const char *mark = "+-*";
    const int dr[] = {-1, 0, 1, 0};
    const int dc[] = {0, 1, 0, -1};
    int n, m;
    const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    inline int Min(int a, int b){ return a < b ? a : b; }
    inline int Max(int a, int b){ return a > b ? a : b; }
    inline LL Min(LL a, LL b){ return a < b ? a : b; }
    inline LL Max(LL a, LL b){ return a > b ? a : b; }
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    queue<string> q[15];
    char s[50];
     
    int main(){
        int T;  cin >> T;
        for(int kase = 1; kase <= T; ++kase){
            printf("Case #%d :
    ", kase);
            scanf("%d %d", &n, &m);
            for(int i = 1; i <= n; ++i)
                while(!q[i].empty())  q[i].pop();
            int x, y, k;
            while(m--){
                scanf("%d", &x);
                if(0 == x){
                    scanf("%d %d", &y, &k);
                    for(int i = 0; i < k && q[y].size() > 0; ++i){
                        printf("%s
    ", q[y].front().c_str());
                        q[y].pop();
                    }
                }
                else if(1 == x){
                    scanf("%s %d", s, &y);
                    q[y].push(s);
                }
                else if(2 == x){
                    scanf("%d", &y);
                    printf("%d
    ", q[y].size());
                }
            }
        }
        return 0;
    }
    
  • 相关阅读:
    转载【Ubuntu】Ubuntu14.04虚拟机调整窗口大小自适应VMware14窗口
    【ubuntu】安装输入法
    【虚拟机ubuntu】安装之后安装VMware tools
    【虚拟机ubuntu设置ssh】ssh连不上问题解决方法
    JavaScript常用函数
    Label自适应高度
    xcode 删除文件后编译会出现*** is missing from working copy
    找window的三种方法
    怎么查看Mac电脑的开机记录?
    iOS 跳转到系统的设置界面
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5875587.html
Copyright © 2011-2022 走看看