zoukankan      html  css  js  c++  java
  • HDU1434(终于用优先队列a了一题。。。了解度+1)

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<string.h>
    #include<queue>
    #include<vector>
    #define maxint 999999999
    #define MAXN 10005
    #define ll long long
    using namespace std;
    
    int n,m,k,flag,num;
    ll sum;
    int Mark[MAXN],st[MAXN],vis[MAXN];
    
    struct Q{
        char name[25];
        int val;
    };
    
    bool operator <(const Q &x,const Q &y){
        int Min=min(strlen(x.name),strlen(y.name));
        if(x.val!=y.val)
            return  x.val>y.val;
        for(int i=0;i<Min;i++){
            if(x.name[i]!=y.name[i])
                return x.name[i]<y.name[i];
        }
    }
    
    int main()
    {
        int l,a,b,c,d;
        char str[20];
    
        while(scanf("%d %d",&n,&m)!=EOF){
            Q z;
            priority_queue<Q>q[MAXN];
            for(int i=1;i<=n;i++){
                scanf("%d",&l);
                for(int j=1;j<=l;j++){
                    scanf("%s %d",z.name,&z.val);
                    q[i].push(z);
                }
            }
            for(int i=1;i<=m;i++){
                scanf("%s",str);
                if(strlen(str)==4){
                 scanf("%d %d",&a,&b);
                 while(!q[b].empty()){
                     q[a].push(q[b].top());
                     q[b].pop();
                 }
                }
                else if(strlen(str)==6){
                    scanf("%d",&c);
                    printf("%s
    ",q[c].top().name);
                    q[c].pop();
                }
                else if(strlen(str)==5){
                    Q w;
                    scanf("%d",&d);
                    scanf("%s %d",w.name,&w.val);
                    q[d].push(w);
                }
            }
            for(int i=1;i<n;i++){
                while(!q[i].empty()){
                    q[i].pop();
                }
            }
        }return 0;
    }
  • 相关阅读:
    HTML th nowrap 属性
    C 语言实例 – 判断闰年
    Java MySQL 连接
    Linux shapecfg命令
    C 简介
    Java 之 HashSet 集合
    Java 之 Set 接口
    Java 之 LinkedList 集合
    Java 之 List 接口
    JavaScript 之 事件(详解)
  • 原文地址:https://www.cnblogs.com/ziranduhuo/p/6032854.html
Copyright © 2011-2022 走看看