1555:inversion Sequence
Time Limit:2 Sec Memory limit:256 MB
submit:107 solved:34
Description
For sequence i1, I2, i3, ..., in, we set AJ to is the number of members in the sequence which is prior to J and greater to J at the same time. The sequence A1, A2, A3, ..., an are referred to as the inversion sequence of the original sequence (I1, I2, i3, ..., in). For example, sequence 1, 2, 0, 1, 0 are the inversion sequence of sequence 3, 1, 5, 2, 4. Your task is to the find a full permutation of 1~n, which is an original sequence of a given inversion sequence. If There is no permutation meets the conditions please output "no solution".
Input
There is several test cases.
Each test case contains 1 positive integers N on the first line. (1≤n≤10000).
followed in the next line are an inversion sequence A1, A2, A3, ..., an (0≤aj < N)
The input would finish with the end of file.
Output
For each case, please output the permutation of 1~n on one line. If There is no permutation meets the conditions, please output "no solution".
Sample Input
51 2 0 1 030 0 021 1
Sample Output
3 1 5 2 2 3No Solution
HINT Source
Problem solving: This topic AH. Hard to read!
Just look at the examples.
1 2 0) 1 0
This expression in the 1-n arrangement, there is this arrangement, the number 1 front only 1 is bigger than him, the number 2 front only 2 is bigger than him, the number 3 front only 0 is bigger than him, the number 4 front only 1 is bigger than him, the number 5 front 0 is bigger than him.
So answer 3 1 5 2 4
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =10010;4vector<int>v;5 intD[maxn],n;6 intMain () {7 while(~SCANF ("%d",&N)) {8 for(inti =1; I <= N; ++i)9scanf"%d", d+i);Ten v.clear (); One BOOLFlag =true; A for(inti = n; i >0; --i) { - if(V.size () <D[i]) { -Flag =false; the Break; - } -V.insert (V.begin () +d[i],i); - } + if(flag) { -Flag =false; + for(inti =0; I < v.size (); ++i) { A if(flag) Putchar (' '); atprintf"%d", V[i]); -Flag =true; - } -Putchar ('\ n'); -}ElsePuts"No Solution"); - } in return 0; -}View Code
Csuoj 1555 Inversion Sequence