zoukankan      html  css  js  c++  java
  • Lehmer Code

    According to Wikipedia: "In mathematics and in particular in combinatorics, the Lehmer code is a particular way to encode each possible permutation of a sequence of n numbers." To be more specific, for a given permutation of items {A1​​, A2​​, ⋯, An​​}, Lehmer code is a sequence of numbers {L1​​, L2​​, ⋯, Ln​​} such that Li​​ is the total number of items from Ai​​ to An​​ which are less than Ai​​. For example, given { 24, 35, 12, 1, 56, 23 }, the second Lehmer code L2​​ is 3 since from 35 to 23 there are three items, { 12, 1, 23 }, less than the second item, 35.

    Input Specification:

    Each input file contains one test case. For each case, the first line gives a positive integer N (≤). Then N distinct numbers are given in the next line.

    Output Specification:

    For each test case, output in a line the corresponding Lehmer code. The numbers must be separated by exactly one space, and there must be no extra space at the beginning or the end of the line.

    Sample Input:

    6
    24 35 12 1 56 23
    
     

    Sample Output:

    3 3 1 0 1 0
     1 #include<bits/stdc++.h>
     2 #include<ext/pb_ds/assoc_container.hpp>
     3 #include<ext/pb_ds/tree_policy.hpp>
     4 using namespace __gnu_pbds;
     5 using namespace std;
     6 int main()
     7 {
     8 //    freopen("data.txt","r",stdin);
     9     int n,x,c1,c2;
    10     tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> tr;
    11     scanf("%d",&n);
    12     vector<int> v(n);
    13     for(int i=0;i<n;i++)
    14     scanf("%d",&v[i]);
    15     for(int i=n-1;i>-1;i--)
    16     {
    17         tr.insert(v[i]);
    18         v[i]=tr.order_of_key(v[i]);
    19     }
    20     printf("%d",v[0]);
    21     for(int i=1;i<n;++i)
    22     printf(" %d",v[i]);
    23     return 0;
    24 }
    诚者,君子之所守也。
  • 相关阅读:
    题解 P2812 【校园网络【[USACO]Network of Schools加强版】】
    拓展卢卡斯定理(伪)
    [洛谷P3807] 【模板】卢卡斯定理
    一道使用Fibonnaci数列通项公式的趣味题目
    [洛谷P3292] [SCOI2016]幸运数字
    [洛谷P3812] 【模板】线性基
    [洛谷P3857] [TJOI2008]彩灯
    2019.06.17课件:[洛谷P1310]表达式的值 题解
    常数PK系列汇总
    关于BFS和dijkstra(2019.04.20)
  • 原文地址:https://www.cnblogs.com/SkystarX/p/12285803.html
Copyright © 2011-2022 走看看