zoukankan      html  css  js  c++  java
  • [LA3135]node形式的优先队列

    n个触发器,每个触发器每period秒就产生一个编号为qnum的事件,求前k个事件。

    n<=1000  k<=10000

    node形式的优先队列

    主要在于重载小于号,确定优先顺序。

     1 #include<cstdio>
     2 #include<cstdlib>
     3 #include<cstring>
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<cmath>
     7 #include<vector>
     8 #include<map>
     9 #include<queue>
    10 using namespace std;
    11 
    12 struct node{
    13     int qnum,period,time;
    14     bool operator < (const node &a) const {
    15         return time > a.time || ( time == a.time  && qnum > a.qnum);
    16     }
    17 };
    18 
    19 priority_queue<node> q;
    20 char s[20];
    21 
    22 int main()
    23 {
    24     //freopen("a.in","r",stdin);
    25     //freopen("a.out","w",stdout);
    26     
    27     node x;
    28     while(scanf("%s",s) && s[0]!='#')
    29     {
    30         scanf("%d%d",&x.qnum,&x.period);
    31         x.time=x.period;
    32         q.push(x);
    33     }
    34     
    35     int k;
    36     scanf("%d",&k);
    37     while(k--)
    38     {
    39         x=q.top();q.pop();
    40         printf("%d
    ",x.qnum);
    41         x.time+=x.period;
    42         q.push(x);
    43     }
    44     
    45     return 0;
    46 }
  • 相关阅读:
    POJ 1680 Fork() Makes Trouble
    课堂改进意见
    梦断代码 读后感3
    梦断代码 读后感2
    找一问题
    软件评价——搜狗输入法
    《梦断代码》读后感1
    站立会议第十天
    站立会议第九天
    站立会议第八天
  • 原文地址:https://www.cnblogs.com/KonjakJuruo/p/9458972.html
Copyright © 2011-2022 走看看