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<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", &A[I].S); for(i=1; i<=n;i++) {scanf("%d", &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<=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)