Uvalive 3135--argus+ precedence rules for custom priority queues

Source: Internet
Author: User

Topic Link: Click to enter
Just test instructions more difficult to understand, after reading the problem can be fully used in priority queue water past. The first priority rule for learning to customize a priority queue is to overload the < operator in the struct.

The code is as follows:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>using namespace STD;typedef structnode{intId,num;intT/// Custom Priority queue priority by overloading < operator     friend BOOL operator< (node N1,node n2) {if(N1.num==n2.num)returnn1.id>n2.id;returnn1.num>n2.num; }}p; P p1,p2;priority_queue<p>q;intMain () {Charstr[ -];intb;//freopen ("In.txt", "R", stdin);       while(scanf('%s ', str)) {if(strcmp(STR,"#")==0) Break;scanf("%d%d", &p1.id,&p1.num);            P1.t=p1.num;      Q.push (p1); }intKscanf("%d", &k); while(k--)  {p2=q.top (); Q.pop ();printf("%d\n", p2.id);             p2.num+=p2.t;      Q.push (p2); }return 0;}

Uvalive 3135--argus+ precedence rules for custom priority queues

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.