csu 1555: Inversion Sequence(vector)

来源:互联网 发布:stat是什么软件 编辑:程序博客网 时间:2024/06/11 14:08

1555: Inversion Sequence

Time Limit: 2 Sec  Memory Limit: 256 MB
Submit: 360  Solved: 121
[Submit][Status][Web Board]

Description

For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence which are prior to j and greater to j at the same time. The sequence a1, a2, a3, … , aN is referred to as the inversion sequence of the original sequence (i1, i2, i3, … , iN). For example, sequence 1, 2, 0, 1, 0 is the inversion sequence of sequence 3, 1, 5, 2, 4. Your task is to find a full permutation of 1~N that is an original sequence of a given inversion sequence. If there is no permutation meets the conditions please output “No solution”.

Input

There are several test cases.
Each test case contains 1 positive integers N in the first line.(1 ≤ N ≤ 10000).
Followed in the next line is an inversion sequence a1, a2, a3, … , aN (0 ≤ aj < N)
The input will finish with the end of file.

Output

For each case, please output the permutation of 1~N in 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 41 2 3No solution

HINT

给你一个序列a[n],要你按照要求去构造一个序列b。

序列a[i]表示序列b中的i前面有a[i]个数比i大。

#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<vector>#define eps 1e-8#define N 10100using namespace std;int n;int a[N];int main() {    while(~scanf("%d",&n)) {        for(int i=1; i<=n; i++)            scanf("%d",&a[i]);        vector<int>vec;        bool flag=1;        for(int i=n; i>=1; i--) {            if(a[i]>vec.size()) {                flag=0;                break;            }            vec.insert(vec.begin()+a[i],i);        }        if(!flag)printf("No solution\n");        else {            for(int i=0; i<vec.size(); i++) {                if(i<vec.size()-1)                    printf("%d ",vec[i]);                else                    printf("%d\n",vec[i]);            }        }    }    return 0;}



0 0