zoukankan      html  css  js  c++  java
  • poj1281

    简单题

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <queue>
    using namespace std;

    #define maxn 1000005
    #define maxm 10004

    struct Node1
    {
    int a;
    Node1(
    int aa) :
    a(aa)
    {
    }
    };

    struct Node2
    {
    int a;
    Node2(
    int aa) :
    a(aa)
    {
    }
    };

    int m, n, p;
    int now, f[maxn], cnt;
    int num[maxm];

    priority_queue
    <Node1> q1;
    priority_queue
    <Node2> q2;

    bool operator <(const Node1 &a, const Node1 &b)
    {
    return a.a > b.a;
    }

    bool operator <(const Node2 &a, const Node2 &b)
    {
    return a.a < b.a;
    }

    void work()
    {
    cnt
    ++;
    bool found = false;
    if (p == 1)
    {
    Node1 x(
    -1);
    while (!q1.empty())
    {
    x
    = q1.top();
    q1.pop();
    if (num[x.a] != 0)
    {
    found
    = true;
    break;
    }
    }
    if (num[x.a])
    num[x.a]
    --;
    if (now < n && f[now] == cnt)
    {
    if (found)
    printf(
    "%d\n", x.a);
    else
    printf(
    "-1\n");
    now
    ++;
    }
    }
    else
    {
    Node2 x(
    -1);
    while (!q2.empty())
    {
    x
    = q2.top();
    q2.pop();
    if (num[x.a] != 0)
    {
    found
    = true;
    break;
    }
    }
    if (num[x.a])
    num[x.a]
    --;
    if (now < n && f[now] == cnt)
    {
    if (found)
    printf(
    "%d\n", x.a);
    else
    printf(
    "-1\n");
    now
    ++;
    }
    }
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    bool first = true;
    while (scanf("%d%d", &m, &n) != EOF)
    {
    while (!q1.empty())
    q1.pop();
    while (!q2.empty())
    q2.pop();
    if (first)
    first
    = false;
    else
    putchar(
    '\n');
    for (int i = 0; i < n; i++)
    scanf(
    "%d", &f[i]);
    memset(num,
    0, sizeof(num));
    p
    = 1;
    char st[5];
    now
    = 0;
    cnt
    = 0;
    while (scanf("%s", st), st[0] != 'e')
    {
    if (st[0] == 'a')
    {
    int a;
    scanf(
    "%d", &a);
    q1.push(Node1(a));
    q2.push(Node2(a));
    num[a]
    ++;
    }
    else if (st[0] == 'p')
    {
    int a;
    scanf(
    "%d", &a);
    p
    = a;
    }
    else
    work();
    }
    }
    return 0;
    }
  • 相关阅读:
    Android kotlin jsoup解析网页html代码
    Android kotlin 判断网络状态
    ASP.NET设计模式笔记1
    C# SMTP发送邮件
    SQL连接数和CPU使用情况查询
    Grafana笔记
    Docker笔记
    solidity学习(四)---storage和memory关键字
    e-book
    solidity学习(四)-- Require(), Assert(), Revert()的用法和区别
  • 原文地址:https://www.cnblogs.com/rainydays/p/2135415.html
Copyright © 2011-2022 走看看