Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5360
Priority Queue + greedy. (Feel this greedy in the Challenge Program design competition, there is a similar, interested can be found.) )
Write priority queue priority judgment when the Maxx written Minn is also drunk, adjusted for 2 hours only to find. It should be more careful.
The initialization of the lower limit is less than the current number of people in the queue, and then determine whether the upper limit and the current number of compliance, if met, the current number of +1, the person out of the team. Also write down the order. The lower bound is then pressed into the queue.
1#include <cstdio>2#include <cstdlib>3#include <cstring>4#include <algorithm>5#include <iostream>6#include <cmath>7#include <cctype>8#include <queue>9#include <map>Ten#include <Set> One#include <stack> A#include <list> -#include <vector> - the using namespacestd; - - -typedefstructNode { + intMaxx; - intMinn; + intID; AFriendBOOL operator<(Node A, Node B) { at returnA.maxx >B.maxx; - } - }node; - - BOOLCMP (Node A, Node B) { - returnA.minn <B.minn; in } - to Const intMAXN =1000010; + Node PEO[MAXN]; -Priority_queue<node>PQ; the intORD[MAXN]; * intN; $ Panax Notoginseng intMain () { - //freopen ("in", "R", stdin); the intT; +scanf"%d", &T); A while(t--) { the intCNT =0; + while(!Pq.empty ()) { - Pq.pop (); $ } $scanf"%d", &n); - for(inti =1; I <= N; i++) { -scanf"%d", &Peo[i].minn); thePeo[i].id =i; - }Wuyi for(inti =1; I <= N; i++) { thescanf"%d", &Peo[i].maxx); - } WuSort (peo+1, peo+n+1, CMP); - intCur =0;//How many people are there now? About intK =1; $ while(Peo[k].minn <= cur) {//Init -Pq.push (peo[k++]); - } - while(!Pq.empty ()) { A if(Pq.top (). Maxx >=cur) { +cur++; the } -ord[cnt++] =pq.top (). ID; $ Pq.pop (); the while(Peo[k].minn <= cur && k <=N) { thePq.push (peo[k++]); the } the } -printf"%d\n", cur); in for(inti =0; I < CNT; i++) { theprintf"%d", Ord[i]); the } About for(inti = k; I <= N; i++) { theprintf"%d", peo[i].id); the } theprintf"\ n"); + } - return 0; the}
[HDOJ5360] Hiking