Title Address: HDU 5349
The priority queue of water is good, but note that if the queue after the 2 operation is empty, the value of Max is-inf.
#include <stdio.h>#include <math.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <sstream>#include <algorithm>#include <set>#include <queue>#include <stack>#include <map>using namespace STD;typedef Long LongLL;Const intinf=0x3f3f3f3f;Const DoublePi=ACOs(-1.0);Const Doubleesp=1e-6;Const intmaxn=1e6+Ten;intMain () {intN,m,k;intMax; while(~scanf("%d", &n)) {priority_queue<int>q; Max=-inf; while(n--) {scanf("%d", &m);if(m==1){scanf("%d", &k); Q.push (k); Max=max (MAX,K); }Else if(m==2){if(Q.empty ())Continue; Q.pop ();if(Q.empty ()) Max=-inf; }Else if(m==3){if(Q.empty ())puts("0");Else printf("%d\n", Max); } } }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5349 (2015 + school 5)-mzl ' s simple problem (priority queue)