forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP24.cpp
More file actions
59 lines (59 loc) · 1.17 KB
/
Copy pathP24.cpp
File metadata and controls
59 lines (59 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<iostream>
#include<fstream>
#include<string>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#define MAXN 1000000
#define LL long long
#define eps 1e-6
#define inf 0x3f3f3f3f
using namespace std;
int vis[10],fa[10];
int main()
{
LL p=0LL;
int k=9;
fa[0] = 1;
for(int i=1;i<=9;i++)
fa[i] = fa[i-1]*i;
for(int i=0;i<=9;)
{
if(vis[i]==0)
{
p+=fa[k];
if(p>=MAXN)
{
if(k>0)
p -= fa[k];
vis[i] =10-k;
k--;
if(k==-1)//´Ë´¦p±ØÈ»µÈÓÚMAXN
break;
i=0;
continue;
}
else
i++;
}
else i++;
}
printf("The millionth lexicographic permutation is:\n");
for(int i=1;i<=10;i++)
{
for(int j=0;j<10;j++)
if(vis[j]==i)
printf("%d",j);
}
printf("\n");
}