fzu 2184 逆序数还原

FZU 2184 逆序数还原

http://acm.fzu.edu.cn/problem.php?pid=2184

 Problem 2184 逆序数还原

Accept: 94    Submit: 165
Time Limit: 1000 mSec    Memory Limit : 32768 KB

 Problem Description

有一段时间Eric对逆序数充满了兴趣,于是他开始求解许多数列的逆序数(对于由1...n构成的一种排列数组a,逆序数即为满足i<j,ai>aj的数字对数),但是某天他发现自己遗失了原来的数列,只留下之前计算过程中留下的各个数字对应的逆序数,现在请你帮他还原出原序列。

 Input

数据有多组,请处理到文件结尾。

每组数据第一行为一个整数N(1<=N<=1000),表示该序列的数字个数。

第二行为N个整数,第i个数字表示排在ai之后比ai小的数字个数。

 Output

输出为一行N个整数,表示原数列。

 Sample Input

5
2 0 1 0 0

 Sample Output

3 1 4 2 5
 
分析:
首先将数组初始化为1……N,想到后面还会有“删除”操作,想到用STL 里的vector容器。
AC代码:
 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <stdlib.h>
 4 #include <algorithm>
 5 #include <string.h>
 6 #include <string>
 7 #include <math.h>
 8 #include <map>
 9 #include <set>
10 #include <vector>
11 #include <stack>
12 #include <queue>
13 
14 using namespace std;
15 
16 const int INF = 0x3f3f3f3f;
17 const int MAX = 1000 + 10;
18 const double eps = 1e-7;
19 const double PI = acos(-1.0);
20 
21 vector<int> v;
22 int a[MAX];
23 
24 int main()
25 {
26     int n;
27     while(~scanf("%d", &n))
28     {
29         v.clear();
30         int i , x;
31         for(i = 1; i <= n; i++)
32             v.push_back(i);
33         vector<int>::iterator it;
34         for(i = 1; i <= n; i++)
35         {
36             scanf("%d", &x);
37             a[i] = v[x];
38             it = v.begin() + x;
39             v.erase(it);
40         }
41         printf("%d", a[1]);
42         for(i = 2; i <= n; i++)
43             printf(" %d", a[i]);
44         puts("");
45     }
46     return 0;
47 }
View Code

 

转载于:https://www.cnblogs.com/jeff-wgc/p/4449386.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值