zoukankan      html  css  js  c++  java
  • hdu 5437 Alisha’s Party 优先队列

    #include<bits/stdc++.h>
    using namespace std;
    const int N=150000+5;
    struct node
    {
        int v,id;
        char s[200+5];
        friend bool operator <(node n1,node n2)
        {
            if(n1.v==n2.v) return n1.id>n2.id;
            return n1.v<n2.v;
        }
    };
    node a[N];
    
    struct data
    {
        int num,cnt;
    } b[N];
    
    bool cmp(data n1,data n2)
    {
        return n1.num<n2.num;
    }
    
    int c[100+5],d[N];
    priority_queue<node>q;
    int main()
    {
        int _,i,j,k,m,p,cnt,st,t;
        scanf("%d",&_);
        while(_--)
        {
            scanf("%d%d%d",&k,&m,&p);
            for(i=0; i<k; i++)
            {
                scanf("%s%d",a[i].s,&a[i].v);
                a[i].id=i;
            }
            for(i=0; i<m; i++)
                scanf("%d%d",&b[i].num,&b[i].cnt);
            sort(b,b+m,cmp);
            for(i=0; i<p; i++)
                scanf("%d",&c[i]);
            while(!q.empty()) q.pop();
            cnt=1;
            j=0;
            for(i=0; i<m; i++)
            {
                for(; j<b[i].num; j++)
                    q.push(a[j]);
                for(t=0; t<b[i].cnt; t++)
                {
                    if(q.empty()) break;
                    d[cnt++]=q.top().id;
                    q.pop();
                }
            }
            for(;j<k; j++)
                q.push(a[j]);
    
            while(!q.empty())
            {
                d[cnt++]=q.top().id;
                q.pop();
            }
            st=0;
            for(i=0; i<p; i++)
            {
                if(st) printf(" ");
                else st++;
                printf("%s",a[d[c[i]]].s);
            }
            if(st) printf("
    ");
        }
        return 0;
    }

    版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

  • 相关阅读:
    Html 回顾
    Parallel 并行编程
    Task---常用的多线程(基于多线程线程)
    Threadpool 可以对线程加以管理的封装
    AsyncThreads---异步多线程
    Abstract 封装,继承,多态
    IO&&Serize 利用线程Thread.Sleep实现"自动输出"
    Ling && Lambda
    Delegate&&Event
    Delegate &&Lambda
  • 原文地址:https://www.cnblogs.com/xryz/p/4847776.html
Copyright © 2011-2022 走看看