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

CSUOJ 1555 Inversion Sequence

时间:2015-03-31 00:19:26      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:

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 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

 

Source

解题:这个题目啊。。难读啊!

还是看例子吧


1 2 0 1 0

这个表示在1-N的排列中,存在这种排列,数字1前面只有1个数比他大,数字2前面只有2个比他大,数字3前面只有0个比他大,数字4前面只有1个比他大,数字5前面0个比他大。

所以答案 3 1 5 2 4

技术分享
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 10010;
 4 vector<int>v;
 5 int d[maxn],n;
 6 int main(){
 7     while(~scanf("%d",&n)){
 8         for(int i = 1; i <= n; ++i)
 9             scanf("%d",d+i);
10         v.clear();
11         bool flag = true;
12         for(int i = n; i > 0; --i){
13             if(v.size() < d[i]){
14                 flag = false;
15                 break;
16             }
17             v.insert(v.begin()+d[i],i);
18         }
19         if(flag){
20             flag = false;
21             for(int i = 0; i < v.size(); ++i){
22                 if(flag) putchar( );
23                 printf("%d",v[i]);
24                 flag = true;
25             }
26             putchar(\n);
27         }else puts("No solution");
28     }
29     return 0;
30 }
View Code

 

CSUOJ 1555 Inversion Sequence

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4379405.html

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