"Priority queue Multi-merge" Uvalive 3135 Argus

Source: Internet
Author: User

Uvalive 3135 Argus

http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18684 Test Instructions


Write a system to execute a series of REGISTER commands: Register q_num Period, each command execution cycle is Period, execution event Q_num, if the event occurs simultaneously, the priority execution Q_num small.

Example

Sample Input
Register 2004 200
Register 2005 300
#
5
Sample Output
2004
2005
2004
2004
2005

Ideas★ Typical Multi-path merge problem, with priority queue to maintain the next event that will occur, priority queue content to advance defining priority Levels, Total time complexity O (KLOGN)

Reference Code
#include <bits/stdc++.h>using namespace STD;Const int_max =2e4+Ten;Chars[ -];intNstructitem{intQ_num,period,time;BOOL operator< (ConstItem &a)Const{//const is essential to explain the low priority   return(Time > A.time) | | (Time = = A.time && q_num > A.q_num); }};p riority_queue<item>pq;intMain () {#ifndef Online_judgeFreopen ("Input.txt","R", stdin);#endif //Online_judge Item item; while(scanf('%s ', s) = =1&& s[0] !=' # '){scanf("%d%d", &item. Q_num,&item.    Period); Item.time = Item.    Period; Pq.push (item); }scanf("%d", &n); for(inti =0; I < n; + + i) {item = Pq.top ();//Heap TopPq.pop ();printf("%d\n", item.    Q_num); Item.time + = Item. Period;//Update the time of the next eventPq.push (item); }return 0;}
    • Bold Ctrl + B
    • Italic Body Ctrl + I
    • ReferenceCtrl + Q
    • Insert LinkCtrl + L
    • Inserting codeCtrl + K
    • Insert PictureCtrl + G
    • Promote titleCtrl + H
    • Ordered listCtrl + O
    • Unordered listCtrl + U
    • LineCtrl + R
    • RevokeCtrl + Z
    • RedoCtrl + Y

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

"Priority queue Multi-merge" Uvalive 3135 Argus

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.