zoukankan      html  css  js  c++  java
  • Perpetuum Mobile

    题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=197228

    题意:

           给定n个数(即1~n),已知其组成的排列逆序数为k,求这n个数的排列的排列情况之一。(与已知排列求逆序数相反)

    案例:

               Input
         4 5
              Output
         4 2 3 1
               Input
         5 7
              Output
         4 2 5 3 1
               Input
         6 0
              Output

                1 2 3 4 5 6

    分析:

            不用想得太过复杂,找出自己能清楚的一种最简单排列方式即可,我所采用的排序方式具体怎样讲解不知道,但举个例子,如果把数n放首位,则后面摆放的数肯定为1~n-1,则但就n这一数来说产生了n-1个逆序数,而如果把1放首位的话,则其后摆放的数定为2~n,则1产生的逆序数为0。大概就是这么个思路了。
    源代码:

     1 #include<cstdio>
     2 int main()
     3 {
     4     int n;
     5     long long k;
     6     while(scanf("%d%lld",&n,&k)!=EOF)
     7     {
     8         int p=1,q=n;        
     9         for(int i=1;i<n;i++)
    10         {
    11             if(k>=n-i)
    12             {
    13                 printf("%d ",q);
    14                 q--;
    15                 k-=n-i;
    16             }
    17             else
    18             {
    19                 printf("%d ",p);
    20                 p++;
    21             }
    22         }
    23         printf("%d
    ",p);
    24     }
    25     return 0;
    26 }
  • 相关阅读:
    c# GDI+ 绘制矩形圆角
    ActivityManager
    PowerDesigner15 下载 数据库建模工具
    IaaS、PaaS和SaaS
    discuz 社区工具
    c# 字符串比较方法
    android adb 命令大全
    unity
    backtrack5 中文网
    aws
  • 原文地址:https://www.cnblogs.com/huaszjh/p/4719115.html
Copyright © 2011-2022 走看看