Title: Give a number (beginning with 0), take out the D number, so that the remaining number is the largest (the order can not be changed).
Problem analysis: Take out the D numbers, and leave n-d numbers left. The equivalent of the number of n numbers in order to select the n-d number of the largest, of course, the use of window sliding priority selection of large.
The code is as follows:
# include<iostream># include<cstdio># include<cstring># include<algorithm>using namespace std;struct num{int val,id;}; Num Num[100005],que[100005];char p[100005];int vis[100005];void solve (int k,int l) {int head=0,tail=-1; for (int i=0;i<k-1;++i) {while (head<=tail&&que[tail].val<num[i].val)--tail; ++tail; Que[tail]=num[i]; } int id=-1; for (int i=k-1;i<l;++i) {while (head<=tail&&que[tail].val<num[i].val)--tail; ++tail; Que[tail]=num[i]; while (que[head].id<i-k+1| | Que[head].id<=id) ++head; printf ("%d", que[head].val); Id=que[head].id; } printf ("\ n");} int main () {int n,d; while (scanf ("%d%d", &n,&d) &&n+d) {scanf ("%s", p); int L=strlen (p); for (int i=0;i<l;++i) num[i].val=p[i]-' 0 ', num[i].id=i; Solve (d+1,l); } return 0;}
UVA-11491 Erasing and Winning (monotone queue)