• POJ1442Black Box


    http://poj.org/problem?id=1442

    题意 : 题目中对给出的数字有两种操作ADD(I)操作,将ADD括号里的数字 I 加到数列里边去,然后是自动排好序的,每一个数列前边都会有一个数字ss,代表着前边GET的数量有ss个,GET就是将现有数列显现出来,然后给你N个依次要添加的数字,下边一行是M个数字,代表着每个get前边有的add的数量,然后输出这个序列中第ss个数。

    思路 : 因为要排序,所以就直接用优先队列就好,但是用一个不行,会超时,至于为什么,其实我也不知道,就用了两个,大小根堆一起用,把小根堆里要输出的那个数前边的数字放到大根堆里,循环操作,如果小根堆首元素小于大根堆首元素,就交换这俩元素

    /*7 4
    3 1 -4 2 8 -1000 2
    1 2 6 6
    Sample Output
    3 3 1 2*/
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<queue>
    #include<vector>
    using namespace std ;
    const int maxn = 30100 ;
    int main()
    {
        int m,n ;
        priority_queue<int ,vector<int> ,less<int> >Q;//大根堆
        priority_queue<int ,vector<int> ,greater<int> >QQ;//小根堆
        scanf("%d %d",&m,&n);
        int a[maxn] ;
        for(int i = 1 ; i <= m ; i++)
            scanf("%d",&a[i]) ;
            int be = 1 ,c,b;
        for(int i = 1 ; i <= n ; i++)
        {
            scanf("%d",&b) ;
            for(int j = be ; j <= b ; j++)
            {
                QQ.push(a[j]) ;
                if(!Q.empty()&&Q.top() > QQ.top())
                {
                    c = Q.top() ;
                    Q.pop() ;
                    Q.push(QQ.top());
                    QQ.pop() ;
                    QQ.push(c) ;
                }
            }
            be = b+1 ;
            printf("%d
    ",QQ.top()) ;
            Q.push(QQ.top());
            QQ.pop() ;
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    Web前端开发工程师编程能力飞升之路
    commonJSAMDCMD
    js正则替换十六进制
    JS获取粘贴内容
    ajax跨域访问总结
    需要坚持,能写出自己满意的内容
    【新年献词】我们是南方周末,我们三十而立
    iOS: 动态更改 backBarButtonItem 的 title
    iOS: 计算 UIWebView 的内容高度
    iOS: 在键盘之上显示一个 View
  • 原文地址:https://www.cnblogs.com/luyingfeng/p/3274430.html
Copyright © 2020-2023  润新知