uva 1203 Argus

简介: 点击打开链接uva 1203 思路: 优先队列 分析: 1 题目要求前k个事件的编号,我们利用优先队列来维护即可 2 优先队列保存的是一个struct,因此我们需要重载 s.

点击打开链接uva 1203

思路: 优先队列
分析:
1 题目要求前k个事件的编号,我们利用优先队列来维护即可
2 优先队列保存的是一个struct,因此我们需要重载<

代码:

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int MAXN = 20;

struct Node{
    int numId;
    int period;
    int time;
    // 重载<
    bool operator<(const Node& s)const{
        return (time > s.time || (time == s.time && numId > s.numId));     
    }
};
priority_queue<Node>q;
char str[MAXN];
int k;

int main(){
    int x , y;
    while(scanf("%s" , str) && str[0] != '#'){
         scanf("%d%d" , &x , &y);
         q.push((Node){x , y , y});
    }   
    scanf("%d" , &k);
    while(k--){
         Node tmp = q.top();
         q.pop();
         printf("%d\n" , tmp.numId);
         q.push((Node){tmp.numId , tmp.period , tmp.time+tmp.period});
    }
    return 0;
}



目录
相关文章
uva10038 Jolly Jumpers
uva10038 Jolly Jumpers
37 0
Uva10001 Garden of Eden
Uva10001 Garden of Eden
46 0
uva 10340 all in all
输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串是。
37 0
UVa11968 - In The Airport
UVa11968 - In The Airport
55 0
UVa10123 No Tipping
UVa10123 No Tipping
61 0
uva375 Inscribed Circles and Isosceles Triangles
uva375 Inscribed Circles and Isosceles Triangles
39 0
uva10152 ShellSort
uva10152 ShellSort
61 0
UVa11776 - Oh Your Royal Greediness!
UVa11776 - Oh Your Royal Greediness!
51 0
uva10112 Myacm Triangles
uva10112 Myacm Triangles
42 0
uva127 "Accordian" Patience
uva127 "Accordian" Patience
43 0