HDU 5360 (2015 + school 6)-hiking (priority queue)

Source: Internet
Author: User

Title Address: HDU 5360
Test instructions: Given n individuals, now invite these people to go hiking, but everyone agrees to the invitation on the condition that the number of people who have already agreed to go hiking C must meet C>=l[i]&&c<=ri and ask you what the order of the invitations is to make as many hikers as possible, and if there are multiple optimal solutions, Output any one of them.
Idea: First according to L from small to to sort, put the current fit L into the priority queue, and then the queue of r from small to large sort, greedy choice of R little, and then messed up can be.

#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=1e5+Ten;intVIS[MAXN];intRES[MAXN];structnode{intS,e;intIdBOOL operator< (Node A)Const{returne>a.e; }}a[maxn],t;priority_queue<node>q;intcmpstructNode A,structNode B) {returnA.S&LT;B.S;}intMain () {intT,n,i,j;intCnt,num;scanf("%d", &t); while(t--) {scanf("%d", &n); for(i=1; i<=n;i++)scanf("%d", &AMP;A[I].S); for(i=1; i<=n;i++) {scanf("%d", &AMP;A[I].E);        A[i].id=i; } sort (A +1, a+n+1, CMP); Cnt=0; num=0;memset(Vis,0,sizeof(VIS)); j=1; for(i=1; i<=n;i++) { while(j<=n&&a[j].s<=cnt)            {Q.push (a[j]);           j + +; } while(!q.empty ())            {t=q.top (); Q.pop ();if(CNT&LT;=T.E)                {res[num++]=t.id;                cnt++; vis[t.id]=1; Break; }}} cnt=0;printf("%d\n", num); for(i=0; i<num;i++) {cnt++;if(cnt==n)printf("%d\n", Res[i]);Else                printf("%d", Res[i]); } for(i=1; i<=n;i++) {if(Vis[i])Continue; cnt++;if(cnt==n)printf("%d\n", i);Else                printf("%d", i); }    }return 0;}

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

HDU 5360 (2015 + school 6)-hiking (priority queue)

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.