zoukankan      html  css  js  c++  java
  • 算法提高 排列数 (全排列)

    问题描述
      0、1、2三个数字的全排列有六种,按照字母序排列如下:
      012、021、102、120、201、210
      输入一个数n
      求0~9十个数的全排列中的第n个(第1个为0123456789)。
    输入格式
      一行,包含一个整数n
    输出格式
      一行,包含一组10个数字的全排列
    样例输入
    1
    样例输出
    0123456789
    数据规模和约定
      0 < n <= 10!
     
    next_permutation方法
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <string>
     5 #include <algorithm>
     6 #include <cmath>
     7 #include <queue> 
     8 using namespace std;
     9 
    10 int main()
    11 {
    12     int n;
    13     while(cin>>n){
    14         int a[10]={0,1,2,3,4,5,6,7,8,9};
    15         if(n==1) cout<<"0123456789"<<endl;
    16         int t=1;
    17         while(next_permutation(a,a+10)){
    18             t++;
    19             if(t==n){
    20                 for(int i=0;i<10;i++) cout<<a[i];
    21                 cout<<endl;
    22                 break; 
    23             }
    24         }
    25     }
    26     return 0;
    27 }
  • 相关阅读:
    CSS基础——基本单位
    CSS基础——表格
    CSS基础——列表
    Single-Source Shortest Paths
    Maximum Flow
    Breadth-First Search
    Depth-First Search (III)
    Depth-First Search (II)
    Depth-First Search (I)
    Simple Complete Search
  • 原文地址:https://www.cnblogs.com/shixinzei/p/10562271.html
Copyright © 2011-2022 走看看