Original title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5360
Test instructions
Probably means that everyone has a number to accept the range $[l_i,r_i]$, now you can choose a person from the one who has not been selected, and if the current number fits the person's needs, then this person will be selected. Now lets you output a selection of sequences so that the number of people selected is as much as possible.
Exercises
Greed is good, in general is the number of constantly increasing, each time from the feasible all $l$ choose $r$ the smallest one. As to why this is optimal. Need a brain tonic.
Code:
#include <iostream>#include<queue>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<vector>#include<functional>#defineMax_n 100005using namespacestd;structNode { Public: intVal; intPOS; Node (intVintp): Val (v), POS (p) {} node () {}BOOL operator< (ConstNode &a)Const { returnVal >A.val; }};p Riority_queue<node>que;intN;intT;vector<node>L[max_n];vector<int>G;intL[max_n],r[max_n];BOOLUsed[max_n];voidinit () { for(inti =0; I <= N; i++) l[i].clear (); memset (Used,0,sizeof(used)); G.clear (); while(Que.size ()) Que.pop ();}intMain () {scanf ("%d", &T); while(t--) {scanf ("%d", &N); Init (); for(inti =0; I < n; i++) scanf ("%d", &L[i]); for(inti =0; I < n; i++) scanf ("%d", &R[i]); for(inti =0; I < n; i++) L[l[i]].push_back (node (r[i), I+1)); intAns =0; for(inti =0; I <= N; i++) { for(intj =0; J < L[i].size (); J + +) Que.push (L[i][j]); while(Que.size () && que.top (). val <i) Que.pop (); if(Que.empty ()) {ans=i; Break; } g.push_back (Que.top (). POS); Que.pop (); } printf ("%d\n", ans); for(inti =0; I < g.size (); i++) {printf ("%d", G[i]); Used[g[i]]=1; } for(inti =1; I <= N; i++)if(!used[i]) printf ("%d", i); printf ("\ n"); } return 0;}
Hdoj 5360 Hiking Priority queue + greedy