LA 3135 Argus (优先队列)

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1136

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct Item
{
    int QNum,Period,Time;
    /*bool operator < (const Item &a) const
    {
        return Time > a.Time ||(Time == a.Time &&QNum>a.QNum);
    }*/
    friend bool operator  < (Item a,Item b) {return a.Time>b.Time||(a.Time==b.Time&&a.QNum>b.QNum);}  //比较倾向第二种写法  对 > 来说 小的先出列
};
int main()
{
    priority_queue<Item> pq;
    char s[20];
    while(scanf("%s",s)&&s[0]!=‘#‘)
    {
        Item item;
        scanf("%d%d",&item.QNum,&item.Period);
        item.Time = item.Period;
        pq.push(item);
    }
    int K;
    scanf("%d",&K);
    while(K--)
    {
        Item r=pq.top();
        pq.pop();
        printf("%d\n",r.QNum);
        r.Time +=r.Period;
        pq.push(r);
    }
    return 0;
}
时间: 2024-07-30 20:28:12

LA 3135 Argus (优先队列)的相关文章

LA 3135 Argus (优先队列的简单应用)

A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensordata, Internet traffic, nancial tickers, on-line auctions, and transaction logs such as Web usage logsand telephone call records. Likewise, queries over

la 3135 Argus Data Structure

// la 3135 Argus // 学习一下优先队列的使用吧,题目还是比较简单的 // 刘老师的训练指南p188. // 继续练吧.... #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include &l

(算法竞赛入门经典 优先队列)LA 3135(前K条指令)

A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logs and telephone call records. Likewise, queries o

UVALive - 3135 - Argus (优先队列!!)

UVALive - 3135 Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, financi

【优先队列之多路归并】UVALive 3135 Argus

UVALive 3135 Argus http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18684 题意 编写一个系统执行一系列Register命令:Register Q_num Period,每个命令执行周期是Period,执行事件Q_num:如果事件同时发生,优先执行Q_num小的. 示例 Sample Input Register 2004 200 Register 2005 300 # 5 Sample Output

LA 3135

Argus Time limit: 3.000 seconds A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logs and telephone c

LA-3135 - Argus(优先队列)

3135 - Argus A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensordata, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web usage logsand telephone call records. Likewise

【暑假】[实用数据结构]UVAlive 3135 Argus

UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, fin

LA 3135 (优先队列) Argus

将多个有序表合并成一个有序表就是多路归并问题,可用优先队列来解决. 1 #include <cstdio> 2 #include <queue> 3 using namespace std; 4 5 const int maxn = 1000 + 10; 6 7 struct Node 8 { 9 int time, period, num; 10 bool operator < (const Node& rhs) const 11 { 12 return time