제출 코드
- 재귀를 사용하여 푸는 문제
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
package bronze;
import java.util.Scanner;
public class B1592_yeongsikAndFriends {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
M = sc.nextInt();
L = sc.nextInt();
round = new int[N];
playGame(0);
System.out.println(cnt);
}
static int N, M, L;
static int cnt = 0;
static int[] round;
static void playGame(int n) {
round[n]++;
if(round[n]==M) return;
cnt++;
if(round[n]%2 == 0) playGame((n-L+N)%N);
else playGame((n+L)%N);
}
}