码迷,mamicode.com
首页 > 其他好文 > 详细

csu 1555: Inversion Sequence(vector)

时间:2015-05-18 09:02:45      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:csu 1555 inversion s   stl   

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

5
1 2 0 1 0
3
0 0 0
2
1 1

Sample Output

3 1 5 2 4
1 2 3
No 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 10100

using 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;
}



csu 1555: Inversion Sequence(vector)

标签:csu 1555 inversion s   stl   

原文地址:http://blog.csdn.net/acm_baihuzi/article/details/45801407

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!