[HDOJ5360] Hiking

Source: Internet
Author: User

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

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.