zoukankan      html  css  js  c++  java
  • Project Euler Problem 24 Lexicographic permutations

    Lexicographic permutations

    Problem 24

    A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:

    012   021   102   120   201   210

    What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?


    C++:

    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    const int N = 1000000;
    
    int main()
    {
        int val[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
    
        for(int i=1; i<N; i++)
            next_permutation(val, val+10);
    
        for(int i=0; i<(int)(sizeof(val)/sizeof(int)); i++)
            cout << val[i];
        cout << endl;
    
        return 0;
    }



  • 相关阅读:
    053-606
    053-605
    1019 General Palindromic Number (20分)
    1208. 翻硬币
    754. 平方矩阵 II
    1346. 回文平方
    680. 剪绳子
    1227. 分巧克力
    756. 蛇形矩阵
    429. 奖学金
  • 原文地址:https://www.cnblogs.com/tigerisland/p/7564000.html
Copyright © 2011-2022 走看看