Analysis: The
title tells us a rule consists of a array of arrays become b. The
A = {5,1,4,2,3}, k = 2; when we ask bi, first to the array to find a i = aj; see a1-aj, there are several numbers satisfying ax <= i + , the counted number is the value of k satisfies bi,.
When seeking b1, first find an available position in a array, to give a left side of the number 5; 5> = 1 + 2; so B1 = 1;
when evaluated b2, first find two available positions in a array, to give a the number of left 5,1,4;
5> = 2 + 2; 4> + 2 = 2; = 2 so B2;
and so on.
When the subject is to give us an array b, we seek to have a minimum order of a dictionary array. We can think of the fact that
the position b in the first 0 appears, on the A [1], which satisfies the condition when the value of the minimum value b is a discharge on a [2] (in the program Found updated when b is implemented, so as to satisfy aj> = i + b subscript k-cur (cur = aj) in Found minus one).
----------------
Disclaimer: This article is CSDN blogger "Zheng Yu tune _xiao cheap" in the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/xiao_x_miss/article/details/10132199
#include <stdio.h>
#include <string.h>
#include <algorithm>
the using namespace STD;
int main ()
{
int A [1005], B [1005];
int n-, K;
the while (Scanf ( "% D% D ", & n-, & K) == 2)
{
for (int I =. 1; I <= n-; I ++) Scanf ("% D ", B + I);
for (int I =. 1; I <= n-; I ++)
{
int = CUR. 1;
the while (B [CUR] = 0) CUR ++; // Get latest 0;!
a [I] = CUR;
B [CUR] -; // will put the a the number cur, into b [cur] = - 1, thus marked.
for (int j = 1; j + k <= cur; j ++) b [j] -; // b update array.
}
For (int I =. 1; I <= n-; I ++) the printf (n-I = "% D":!? "% D \ n-", A [I]);
}
return 0;