forked from wandering007/ProjectEuler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP145.cpp
More file actions
62 lines (61 loc) · 1.49 KB
/
P145.cpp
File metadata and controls
62 lines (61 loc) · 1.49 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
60
61
62
#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>
#include<iomanip>
#define MAXN 1000000000
#define MOD 1000000
#define LL long long
#define eps 1e-8
#define inf 0x3f3f3f3f
using namespace std;
/*
0 2 4 6 8
1 3 5 7 9
*/
int Reversible(int n, int digit, bool carried, bool carrying)
{
if((n + 1) / 2 < digit)
{//n is even
if(carried == carrying)
return 1;//中心对称的两位的和与进位要保证对称,同进位或者同不进位
return 0;
}
if((n + 1) / 2 == digit && (n & 1))
{
if(false == carried)
return 0;
return 5; //5, 6, 7, 8, 9 或 0, 1, 2, 3, 4
}
if(false == carried)
{
if(1 == digit)
return 20 * Reversible(n, 2, false, false) + 20 * Reversible(n, 2, true, false);
if(true == carrying)
return 20 * Reversible(n, digit + 1, true, false);
else return 30 * Reversible(n, digit + 1, false, false);
}
else return 25 * Reversible(n, digit + 1, carrying, true);
}
int main()
{
clock_t start = clock();
int num = 0;
for(int i = 1; i <= 9; i++)
num += Reversible(i, 1, false, false);
printf("%d\n", num);
printf("time cost: %lf", (double)(clock() - start) / CLOCKS_PER_SEC);
return 0;
}