蓝桥杯 ADV-188 算法提高 排列数

算法提高 排列数

时间限制:1.0s   内存限制:256.0MB

问题描述

  0、1、2三个数字的全排列有六种,按照字母序排列如下:
  012、021、102、120、201、210
  输入一个数n
  求0~9十个数的全排列中的第n个(第1个为0123456789)。

输入格式

  一行,包含一个整数n

输出格式

  一行,包含一组10个数字的全排列

扫描二维码关注公众号,回复: 9266387 查看本文章

样例输入

1

样例输出

0123456789

数据规模和约定

  0 < n <= 10!

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    string s = "0123456789";
    int n;

    cin >> n;
    n--;
    while (n && next_permutation(s.begin(), s.end()))
        n--;

    cout << s;

    return 0;
}
发布了317 篇原创文章 · 获赞 44 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/liulizhi1996/article/details/104329094
今日推荐