Test instructions: give you an n-bit integer, let you delete the D number, the remaining number should be as large as possible.
Solution: Because the last digit number is determined, and the low number of the answer contribution is not necessarily high number, so preferred to choose the largest and most on the left of the number, but there is a limit, choose this number after the left of the number to ensure enough next choice, so I think of the priority queue, record a message, The position of the selected number, and the position of the previous number, if the current number of the outgoing team is directly discarded in front of the last selected position, the number of the remaining selected after each selection is reduced, the number of conditions that meet the limit increases, and the new number to be selected is added to the queue.
#include <bits/stdc++.h>using namespacestd;Const intMAXN = 1e5+5;structdig{intVal,pos; BOOL operator< (ConstDig & RHS)Const { returnVal < Rhs.val | | (val = = Rhs.val && pos >Rhs.pos); }}D[MAXN];p riority_queue<dig>Q;intn,d;voidSovle () { while(Q.size ()) Q.pop (); inti; for(i =0; I <= D; i++) {Q.push (d[i]); } intNeed = N-d,pre =-1; while(need) { while(Q.top () .pos<pre) Q.pop (); ConstDig &u =Q.top (); if(U.pos = = Nneed) { for(i = u.pos; i < n; i++) printf ("%d", D[i].val); Break; } Pre=U.pos; printf ("%d", U.val); Need--; Q.pop (); Q.push (D[i++]); } Putchar ('\ n');}intMain () {//freopen ("In.txt", "R", stdin); while(SCANF ("%d%d",&n,&d), N) { for(inti =0; I < n; i++) {scanf ("%1d",&d[i].val); D[i].pos=i; } sovle (); } return 0;}
UVA 11491 erasing and Winning prize value (greedy)