csu 1555: Inversion Sequence(vector)

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;
}
时间: 2024-10-01 11:49:27

csu 1555: Inversion Sequence(vector)的相关文章

STL or 线段树 --- CSU 1555: Inversion Sequence

Inversion Sequence Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1555 Mean: 给你一个序列a[n],要你按照要求去构造一个序列b. 序列a[i]表示序列b中的i前面有a[i]个数比i大. 转换一下就是: 已知一个连续的序列(1,2,3,4,...),然后告诉了我们这个序列中每个数前面比本身大的个数,根据这些条件将这个序列调整顺序,找到满足条件的序列. analyse: STL大法好

CSU 1555 Inversion Sequence 给出逆序数求排列 splay

题目链接:点击打开链接 题意: 给出逆序数的值,求原序列(一个1-N的排列) 1, 2, 0, 1, 0 表示1的逆序数是1,2的逆序数是2,3的逆序数是0··· 思路: 从最后一个数开始插,每次插到当前序列的第a[i]个数.. splay模拟 == 这个方法比较直(wu)观(nao),别的方法并没有想出来.. #include <cstdio> #include <iostream> #include <cstring> #include <queue>

1555: Inversion Sequence (通过逆序数复原序列 vector的骚操作!!!)

1555: Inversion Sequence Submit Page    Summary    Time Limit: 2 Sec     Memory Limit: 256 Mb     Submitted: 519     Solved: 195 Description For sequence i1, i2, i3, … , iN, we set aj to be the number of members in the sequence which are prior to j a

CSUOJ 1555 Inversion Sequence

1555: Inversion Sequence Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 107  Solved: 34 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 seq

CSUOJ 1555 Inversion Sequence 线段树

Inversion Sequence Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%lld & %llu 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.

[ACM] SCU 1555 Inversion Sequence (线段树)

http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1555 输入5个数 1 2 0 1 0 表示1前面有1个比它大的数,2前面有2个比它大的数-.. 求一个1~n的排列,比如这个就输出3 1 5 2 4 1前面有1个比它大的数,那么1肯定在第二位 2前面有2个比它大的数,那么2肯定排在第四位,有一位被1占了. 3前面有0个比它大的数,那么3肯定在第一位 维护线段树,叶子结点的值为1,维护和.从左到右找第多少个1就可以了. 比如1前面有1个比它大的数

csu 1555(线段树经典插队模型-根据逆序数还原序列)

1555: Inversion Sequence Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 469  Solved: 167[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

Inversion Sequence(csu 1555)

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 sequen

湖南多校对抗赛(2015.03.28) I Inversion Sequence

题意:给你一个序列a[i],代表 i这个数 在b数列中有多少个值在它前面且比它大,问你求B序列 解题思路:线段树的简单应用,找第几个空,类似二分. 解题代码: 1 // File Name: i.cpp 2 // Author: darkdream 3 // Created Time: 2015年03月28日 星期六 12时56分11秒 4 5 #include<vector> 6 #include<list> 7 #include<map> 8 #include<