• hdu 1873 看病要排队


    http://acm.hdu.edu.cn/showproblem.php?pid=1873

    两种自定义优先级写法

    View Code
     1 #include<iostream>
     2 #include<queue>
     3 #include<string>
     4 using namespace std;
     5 struct Node
     6 {
     7     int time;
     8     int import;
     9     bool operator<(const Node &a) const
    10     {
    11         if(a.import>import) return true;
    12         else if(a.import==import&&a.time<time) return true;
    13         else return false;
    14     }
    15 }p[2002];
    16 int main()
    17 {
    18     
    19     
    20     
    21     int n;
    22     string str1;
    23     string str2;
    24     string str;
    25     int d,i;
    26     Node node;
    27     int count;
    28     while(~scanf("%d",&n))
    29     {
    30         count=1;
    31         priority_queue<Node>doc[4];
    32         while(n--)
    33         {
    34             
    35             
    36             cin>>str;
    37             if(str[0]=='I')
    38             {
    39                 
    40                 
    41                 scanf("%d%d",&d,&i);
    42                 p[count].time=count;
    43                 p[count].import=i;
    44                 doc[d].push(p[count]);
    45                 count++;
    46                 
    47             }
    48             else
    49             {
    50                
    51                
    52                
    53                scanf("%d",&d);
    54                if(doc[d].empty()==true)
    55                {
    56                      printf("EMPTY\n");
    57                      
    58                   }
    59                   
    60                 else 
    61                 {
    62                     
    63                     printf("%d\n",doc[d].top().time);
    64                     doc[d].pop();
    65                 }    
    66             }
    67         }
    68         
    69     }
    70 }
    View Code
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<queue>
     4 #include<algorithm>
     5 using namespace std;
     6 struct patient
     7 {
     8     int num;/*编号*/
     9     int imp;/*重要度*/
    10 }w[1001];
    11 struct comp
    12 {
    13     bool operator()(patient &x,patient &y)/*结构体排序*/
    14     {
    15         if(x.imp<y.imp) return true;
    16         if(x.imp==y.imp&&x.num>y.num) return true;
    17         return false;
    18     }
    19 };
    20 int main()
    21 {
    22     int n,i,a,b,count;
    23     char str[101];
    24     while(~scanf("%d",&n))
    25     {
    26         priority_queue<patient,vector<patient>,comp>doc[4];/*优先队列*/
    27         count=1;
    28         while(n--)
    29         {
    30             scanf("%s",str);
    31             if(str[0]=='I')
    32             {
    33                 scanf("%d %d",&a,&b);
    34                 w[count].num=count;
    35                 w[count].imp=b;
    36                 doc[a].push(w[count]);/*直接插入一个结构体....*/
    37                 count++;
    38             }
    39             else
    40             {       
    41                 scanf("%d",&a);
    42                 if(doc[a].empty())
    43                 {
    44                     printf("EMPTY\n");
    45                 }
    46                 else
    47                 {
    48                     printf("%d\n",doc[a].top().num);
    49                     doc[a].pop();
    50                 }
    51             }
    52         }
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    轮播插件unsilder 源码解析(二)
    轮播插件unsilder 源码解析(一)---源码解析
    轮播插件unsilder 源码解析(一)---使用
    jquery插件扩展的学习
    基于canvas的陈列订货的分析
    grunt安装和使用教程
    2016订货会项目总结2
    2016工作项目完成总结
    不使用递归法求值
    easy bootstrap模板
  • 原文地址:https://www.cnblogs.com/1114250779boke/p/2626596.html
Copyright © 2020-2023  润新知