zoukankan      html  css  js  c++  java
  • 【优先队列】hdu 1434 幸福列车

    Use priority_queue to simulate :

     1 #include <iostream>
     2 #include <string>
     3 #include <cstdio>
     4 #include <cstring>
     5 #include <queue>
     6 const int MAXN = 10000+10;
     7 using namespace std;
     8 
     9 typedef struct{
    10     string name;
    11     int rp;
    12 }node;
    13 
    14 bool operator <( node x, node y ){
    15     if(x.rp>y.rp) return 1;
    16     else if(x.rp==y.rp && x.name<y.name) return 1;
    17     return 0;
    18 }
    19 
    20 priority_queue <node> q[MAXN];
    21 
    22 int n,m;
    23 node anode;
    24 int main()
    25 {
    26     while(scanf("%d %d",&n,&m)!=EOF){
    27         int t;
    28         for(int i=1;i<=n;i++){
    29             while(!q[i].empty()) q[i].pop();
    30             scanf("%d",&t);
    31             while(t--){
    32                 cin>>anode.name>>anode.rp;
    33                 q[i].push(anode);
    34             }
    35         }
    36 
    37         string cmd;
    38         int a,b,c;
    39         for(int i=1;i<=m;i++){
    40             cin>>cmd;
    41             if(cmd=="GETON"){
    42                 cin>>a>>anode.name>>anode.rp;
    43                 q[a].push(anode);
    44             }
    45             else if(cmd=="JOIN")            {
    46                 scanf("%d %d",&a,&b);
    47                 while(!q[b].empty())                {
    48                     q[a].push(q[b].top());
    49                     q[b].pop();
    50                 }
    51             }
    52             else            {
    53                 scanf("%d",&a);
    54                 cout<<q[a].top().name<<endl;
    55                 q[a].pop();
    56             }
    57         }
    58     }
    59     
    60     
    61     
    62     return 0;
    63 }
  • 相关阅读:
    课后作业
    大道至简第六章读后感
    Ljava.lang.Object;@ba8a1dc
    课后作业
    大道至简第五章读后感
    课后作业加密
    动手动脑
    大道至简第四章读后感
    NEU 解题报告索引
    Aizu 解题报告索引
  • 原文地址:https://www.cnblogs.com/bruce27/p/4439324.html
Copyright © 2011-2022 走看看