zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    测试工程师入门要了解什么?(四)
    测试工程师入门要了解什么?(三)
    测试工程师入门要了解什么?(二)
    测试工程师入门要了解什么?(一)
    测试工程师专业术语
    测试场景标准库
    猜数字
    遍历
    python基础
    python class1
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4449386.html
Copyright © 2011-2022 走看看