-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1003.java
More file actions
71 lines (62 loc) ยท 1.35 KB
/
_1003.java
File metadata and controls
71 lines (62 loc) ยท 1.35 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
63
64
65
66
67
68
69
70
71
package backjoon;
// https://www.acmicpc.net/problem/1003
// ํผ๋ณด๋์น ํจ์
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _1003 {
public static int cntZero = 0;
public static int cntOne = 0;
static int zero_plus_one;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(br.readLine());
StringBuilder sb = new StringBuilder();
for(int i=0; i<T; i++){
int n = Integer.parseInt(br.readLine());
fibonacci(n);
sb.append(cntZero).append(' ').append(cntOne).append("\n");
// cntZero = 0;
// cntOne = 0;
}
System.out.println(sb);
}
// sol1 ์๊ฐ์ด๊ณผ
/*
static int fibonacci(int n){
if(n == 0){
cntZero++;
return 0;
} else if (n == 1){
cntOne++;
return 1;
} else {
return fibonacci(n-1) + fibonacci(n-2);
}
}
*/
// so2 memory 11432 runtime 76
// ๊ท์น์ ์ฐพ์์ ํ๊ธฐ
static void fibonacci(int N) {
// ๋ฐ๋์ ์ด๊ธฐํ ํด์ผํ๋ค.
cntZero = 1;
cntOne = 0;
zero_plus_one = 1;
for (int i = 0; i < N; i++) {
cntZero = cntOne;
cntOne = zero_plus_one;
zero_plus_one = cntZero + cntOne;
}
}
}
/*
input
3
0
1
3
output
1 0
0 1
1 2
*/