https://projecteuler.net/problem=24
Lexicographic permutations
Problem 24
Published on Friday, 16th August 2002, 06:00 pm; Solved by 75662; Difficulty rating: 5%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?
这道题懒得编程了,就纯粹靠手工计算的结果,过程如下:
9!=362880,我们要算第100万个,所以第一个数字排在第三位,也就是 2,接下来要算第274240位数 (1000000 - 9! * 2)
8!=40320,经过计算:8!*6 < 274240 < 8!*7,所以第二个数字,排在剩下数字的第7位,也就是:7,接下来算第32320位数(274240 - 8! * 6)
。
。
。
依次类推:直到剩下最后两位6和0,要求第二位数,那就是60了。
所以结果是:2783915460
用计算机算也一样,懒得写程序了
本文解决了一个排列问题,即求出0到9这十个数字的第100万个字典序排列。通过逐步的手工计算,最终得出答案为2783915460,并解释了每一步的计算逻辑。
1万+

被折叠的 条评论
为什么被折叠?



