-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy path1105-Fi-Binary-Number.cpp
More file actions
77 lines (57 loc) · 860 Bytes
/
Copy path1105-Fi-Binary-Number.cpp
File metadata and controls
77 lines (57 loc) · 860 Bytes
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int a[100];
int dp[100];
int maxi;
int n;
int explore(int sum)
{
if(sum <= 0) {
for (int j = maxi; j >= 0; j--) {
printf("%d", a[j]);
}
printf("\n");
return 0;
}
if(sum == 1) {
a[0] = 1;
maxi = max(maxi, 0);
explore(0);
return 0;
}
for (int i = 0; 1; i++) {
if(dp[i+1] >= sum and dp[i] < sum) {
a[i+1] = 1;
sum = sum - (dp[i]+1);
maxi = max(maxi, i+1);
explore(sum);
break;
}
}
}
int main()
{
int j;
int k;
int t;
int temp;
j = 1;
k = 2;
dp[0] = 1;
for (int i = 1; i < 44; i++) {
dp[i] = dp[i-1] + j;
temp = k;
k = j + k;
j = temp;
}
scanf("%d", &t);
for (int cs = 1; cs <= t; cs++) {
scanf("%d", &n);
memset(a, 0, sizeof(a));
maxi = -1;
printf("Case %d: ", cs);
explore(n);
}
}